From patchwork Sat May 12 01:48:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andy Green X-Patchwork-Id: 39889 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 3976E1CC57; Sat, 12 May 2018 03:49:00 +0200 (CEST) Received: from mail.warmcat.com (mail.warmcat.com [163.172.24.82]) by dpdk.org (Postfix) with ESMTP id 5C7331CC57 for ; Sat, 12 May 2018 03:48:58 +0200 (CEST) From: Andy Green To: dev@dpdk.org Date: Sat, 12 May 2018 09:48:54 +0800 Message-ID: <152608973466.121204.1661982833255592271.stgit@localhost.localdomain> In-Reply-To: <152608956198.121204.14844325841690943774.stgit@localhost.localdomain> References: <152608956198.121204.14844325841690943774.stgit@localhost.localdomain> User-Agent: StGit/unknown-version Subject: [dpdk-dev] [PATCH v5 14/16] app/proc-info: sprintf overrun bug X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" /home/agreen/projects/dpdk/app/proc-info/main.c: In function ‘nic_xstats_display’: /home/agreen/projects/dpdk/app/proc-info/main.c:495:45: error: ‘%s’ directive writing up to 255 bytes into a region 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, ~~~~~~~~~~~~ /home/agreen/projects/dpdk/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]); Signed-off-by: Andy Green Fixes: 2deb6b5246d7 ("app/procinfo: add collectd format and host id") Cc: stable@dpdk.org --- app/proc-info/main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/proc-info/main.c b/app/proc-info/main.c index 539e13243..c20effa4f 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 {