summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorian <ian@FreeBSD.org>2015-03-14 18:11:24 +0000
committerian <ian@FreeBSD.org>2015-03-14 18:11:24 +0000
commit200d20ade218c3fcf14551f82f1d20dfaaa7525c (patch)
treebf1a98c6e82e555a16b58a3df1eb7b859a14714b
parentbc1c82b63ec905c2ba2876aa4005cdc5a2293abc (diff)
downloadFreeBSD-src-200d20ade218c3fcf14551f82f1d20dfaaa7525c.zip
FreeBSD-src-200d20ade218c3fcf14551f82f1d20dfaaa7525c.tar.gz
Use sbuf_new_for_sysctl() instead of plain sbuf_new() to ensure sysctl
string returned to userland is nulterminated. PR: 195668
-rw-r--r--sys/netinet/tcp_hostcache.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/sys/netinet/tcp_hostcache.c b/sys/netinet/tcp_hostcache.c
index b03556f..fa6b5da 100644
--- a/sys/netinet/tcp_hostcache.c
+++ b/sys/netinet/tcp_hostcache.c
@@ -596,7 +596,7 @@ tcp_hc_update(struct in_conninfo *inc, struct hc_metrics_lite *hcml)
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);
}
OpenPOWER on IntegriCloud