The minimum sbuf buffer size is 2 bytes (a byte plus a nulterm), assert that.

Values smaller than two lead to strange asserts that have nothing to do
with the actual problem (in the case of size=0), or to writing beyond the
end of the allocated buffer in sbuf_finish() (in the case of size=1).
This commit is contained in:
Ian Lepore 2015-03-17 21:00:31 +00:00
parent 2834924513
commit 612d9391a4
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=280193

View File

@ -78,6 +78,7 @@ static MALLOC_DEFINE(M_SBUF, "sbuf", "string buffers");
#define SBUF_SETFLAG(s, f) do { (s)->s_flags |= (f); } while (0)
#define SBUF_CLEARFLAG(s, f) do { (s)->s_flags &= ~(f); } while (0)
#define SBUF_MINSIZE 2 /* Min is 1 byte + nulterm. */
#define SBUF_MINEXTENDSIZE 16 /* Should be power of 2. */
#ifdef PAGE_SIZE
@ -192,8 +193,9 @@ sbuf_newbuf(struct sbuf *s, char *buf, int length, int flags)
s->s_buf = buf;
if ((s->s_flags & SBUF_AUTOEXTEND) == 0) {
KASSERT(s->s_size >= 0,
("attempt to create a too small sbuf"));
KASSERT(s->s_size >= SBUF_MINSIZE,
("attempt to create an sbuf smaller than %d bytes",
SBUF_MINSIZE));
}
if (s->s_buf != NULL)