--- sys/kern/subr_sbuf.c.orig +++ sys/kern/subr_sbuf.c @@ -333,8 +333,15 @@ s->s_error = -len; return (s->s_error); } - KASSERT(len > 0 && len <= s->s_len, - ("Bad drain amount %d for sbuf %p", len, s)); + if (len == 0 || len > s->s_len) { + /* + * Drain callback violated its contract. Stop before it + * corrupts the buffer: the KASSERT alone is compiled out + * of production (non-INVARIANTS) kernels. + */ + s->s_error = EDOOFUS; + return (s->s_error); + } s->s_len -= len; /* * Fast path for the expected case where all the data was