DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [dpdk-dev] [PATCH] [pktgen] Fix string truncation warnings
Date: Mon,  7 Jan 2019 12:22:25 -0800	[thread overview]
Message-ID: <20190107202225.4249-1-sthemmin@microsoft.com> (raw)

From: Stephen Hemminger <stephen@networkplumber.org>

The strncatf macro will cause warnings with latest GCC
if the sizeof the destination buffer is smaller than the temporary buffer.

Resolve by adjusting buffer sizes.

Such as:
git/pktgen-dpdk/app/pktgen-capture.c: In function ‘pktgen_set_capture’:
git/pktgen-dpdk/app/pktgen-log.h:114:3: error: ‘strncat’ output may be truncated copying between 0 and 255 bytes from a string of length 1022 [-Werror=stringop-truncation]
   strncat(dest, _buff, sizeof(dest) - strlen(dest) - 1); \
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
git/pktgen-dpdk/app/pktgen-capture.c:246:7: note: in expansion of macro ‘strncatf’
       strncatf(status, "%d%%", pct);
       ^~~~~~~~
cc1: all warnings being treated as errors

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/pktgen-capture.c |  2 +-
 app/pktgen-log.h     | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/app/pktgen-capture.c b/app/pktgen-capture.c
index aee4ff9bd650..0f3f42bdc488 100644
--- a/app/pktgen-capture.c
+++ b/app/pktgen-capture.c
@@ -200,7 +200,7 @@ found_rx_lid:
 			size_t mem_dumped = 0;
 			unsigned int pct = 0;
 
-			char status[256];
+			char status[1024];
 			sprintf(
 			        status,
 			        "\r    Dumping ~%.2fMB of captured data to disk: 0%%",
diff --git a/app/pktgen-log.h b/app/pktgen-log.h
index 46e347b72b3f..8d132d88c748 100644
--- a/app/pktgen-log.h
+++ b/app/pktgen-log.h
@@ -108,11 +108,11 @@ extern "C" {
  * arguments. It formats the string and appends it to the existing string, while
  * avoiding possible buffer overruns.
  */
-#define strncatf(dest, fmt, ...) do {					       \
-		char _buff[1024];						       \
-		snprintf(_buff, sizeof(_buff), fmt, ## __VA_ARGS__);			\
-		strncat(dest, _buff, sizeof(dest) - strlen(dest) - 1);		       \
-} while (0)
+#define strncatf(dest, fmt, ...) do {					\
+		char _buff[1023];					\
+		snprintf(_buff, sizeof(_buff), fmt, ## __VA_ARGS__);	\
+		strncat(dest, _buff, sizeof(dest) - strlen(dest) - 1);	\
+	} while (0)
 
 /* Initialize log data structures */
 void pktgen_init_log(void);
-- 
2.20.1

                 reply	other threads:[~2019-01-07 20:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190107202225.4249-1-sthemmin@microsoft.com \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).