svn commit: r280193 - head/sys/kern
Ian Lepore
ian at FreeBSD.org
Tue Mar 17 21:00:32 UTC 2015
Author: ian
Date: Tue Mar 17 21:00:31 2015
New Revision: 280193
URL: https://svnweb.freebsd.org/changeset/base/280193
Log:
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).
Modified:
head/sys/kern/subr_sbuf.c
Modified: head/sys/kern/subr_sbuf.c
==============================================================================
--- head/sys/kern/subr_sbuf.c Tue Mar 17 20:56:24 2015 (r280192)
+++ head/sys/kern/subr_sbuf.c Tue Mar 17 21:00:31 2015 (r280193)
@@ -78,6 +78,7 @@ static MALLOC_DEFINE(M_SBUF, "sbuf", "st
#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, i
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)
More information about the svn-src-head
mailing list