aboutsummaryrefslogtreecommitdiff
path: root/sys/netinet/tcp_hostcache.c
diff options
context:
space:
mode:
authorIan Lepore <ian@FreeBSD.org>2015-03-14 18:11:24 +0000
committerIan Lepore <ian@FreeBSD.org>2015-03-14 18:11:24 +0000
commit751ccc429dd11478756e225b82b25f4c4dcee5e3 (patch)
treebf1a98c6e82e555a16b58a3df1eb7b859a14714b /sys/netinet/tcp_hostcache.c
parent208264283de784cfea5ffc79690d63ec2c0ddc97 (diff)
downloadsrc-751ccc429dd11478756e225b82b25f4c4dcee5e3.tar.gz
src-751ccc429dd11478756e225b82b25f4c4dcee5e3.zip
Use sbuf_new_for_sysctl() instead of plain sbuf_new() to ensure sysctl
string returned to userland is nulterminated. PR: 195668
Notes
Notes: svn path=/head/; revision=279997
Diffstat (limited to 'sys/netinet/tcp_hostcache.c')
-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 b03556ff67e0..fa6b5daedf95 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);
}