summaryrefslogtreecommitdiff
path: root/app/proc-info
diff options
context:
space:
mode:
authorAndy Green <andy@warmcat.com>2018-05-14 13:01:02 +0800
committerFerruh Yigit <ferruh.yigit@intel.com>2018-05-14 23:32:23 +0200
commit3cef37eb98769935fbc12e01f06d9ac36d430071 (patch)
treeb91450f7def76e1b851065487e90000990a6322f /app/proc-info
parentd7a13d2d1c9d82bd7478d92157352911e4ef3c48 (diff)
downloaddpdk-3cef37eb98769935fbc12e01f06d9ac36d430071.zip
dpdk-3cef37eb98769935fbc12e01f06d9ac36d430071.tar.gz
dpdk-3cef37eb98769935fbc12e01f06d9ac36d430071.tar.xz
app/procinfo: fix sprintf overrun
app/proc-info/main.c: In function ‘nic_xstats_display’: app/proc-info/main.c:495:45: error: ‘%s’ directive writing up to 255 bytes into a regioni of size between 165 and 232 [-Werror=format-overflow=] sprintf(buf, "PUTVAL %s/dpdkstat-port.%u/%s-%s N:%" ^~ PRIu64"\n", host_id, port_id, counter_type, ~~~~~~~~~~~~ app/proc-info/main.c:495:4: note: ‘sprintf’ output between 31 and 435 bytes into a destination of size 256 sprintf(buf, "PUTVAL %s/dpdkstat-port.%u/%s-%s N:%" ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PRIu64"\n", host_id, port_id, counter_type, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ xstats_names[i].name, values[i]); Fixes: 2deb6b5246d7 ("app/procinfo: add collectd format and host id") Cc: stable@dpdk.org Signed-off-by: Andy Green <andy@warmcat.com> Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
Diffstat (limited to 'app/proc-info')
-rw-r--r--app/proc-info/main.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/app/proc-info/main.c b/app/proc-info/main.c
index 539e132..c20effa 100644
--- a/app/proc-info/main.c
+++ b/app/proc-info/main.c
@@ -488,14 +488,18 @@ nic_xstats_display(uint16_t port_id)
if (enable_collectd_format) {
char counter_type[MAX_STRING_LEN];
char buf[MAX_STRING_LEN];
+ size_t n;
collectd_resolve_cnt_type(counter_type,
sizeof(counter_type),
xstats_names[i].name);
- sprintf(buf, "PUTVAL %s/dpdkstat-port.%u/%s-%s N:%"
+ n = snprintf(buf, MAX_STRING_LEN,
+ "PUTVAL %s/dpdkstat-port.%u/%s-%s N:%"
PRIu64"\n", host_id, port_id, counter_type,
xstats_names[i].name, values[i]);
- ret = write(stdout_fd, buf, strlen(buf));
+ if (n > sizeof(buf) - 1)
+ n = sizeof(buf) - 1;
+ ret = write(stdout_fd, buf, n);
if (ret < 0)
goto err;
} else {