Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 17 Mar 2015 21:00:31 +0000 (UTC)
From:      Ian Lepore <ian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r280193 - head/sys/kern
Message-ID:  <201503172100.t2HL0VII010154@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201503172100.t2HL0VII010154>