Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 Mar 2015 18:11:25 +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: r279997 - head/sys/netinet
Message-ID:  <201503141811.t2EIBPeE006504@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ian
Date: Sat Mar 14 18:11:24 2015
New Revision: 279997
URL: https://svnweb.freebsd.org/changeset/base/279997

Log:
  Use sbuf_new_for_sysctl() instead of plain sbuf_new() to ensure sysctl
  string returned to userland is nulterminated.
  
  PR:		195668

Modified:
  head/sys/netinet/tcp_hostcache.c

Modified: head/sys/netinet/tcp_hostcache.c
==============================================================================
--- head/sys/netinet/tcp_hostcache.c	Sat Mar 14 17:35:04 2015	(r279996)
+++ head/sys/netinet/tcp_hostcache.c	Sat Mar 14 18:11:24 2015	(r279997)
@@ -596,7 +596,7 @@ tcp_hc_update(struct in_conninfo *inc, s
 static int
 sysctl_tcp_hc_list(SYSCTL_HANDLER_ARGS)
 {
-	int linesize = 128;
+	const int linesize = 128;
 	struct sbuf sb;
 	int i, error;
 	struct hc_metrics *hc_entry;
@@ -604,8 +604,7 @@ sysctl_tcp_hc_list(SYSCTL_HANDLER_ARGS)
 	char ip6buf[INET6_ADDRSTRLEN];
 #endif
 
-	sbuf_new(&sb, NULL, linesize * (V_tcp_hostcache.cache_count + 1),
-	    SBUF_FIXEDLEN);
+	sbuf_new_for_sysctl(&sb, NULL, linesize, req);
 
 	sbuf_printf(&sb,
 	        "\nIP address        MTU  SSTRESH      RTT   RTTVAR BANDWIDTH "
@@ -642,8 +641,7 @@ sysctl_tcp_hc_list(SYSCTL_HANDLER_ARGS)
 		THC_UNLOCK(&V_tcp_hostcache.hashbase[i].hch_mtx);
 	}
 #undef msec
-	sbuf_finish(&sb);
-	error = SYSCTL_OUT(req, sbuf_data(&sb), sbuf_len(&sb));
+	error = sbuf_finish(&sb);
 	sbuf_delete(&sb);
 	return(error);
 }



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