[dpdk-stable] [PATCH 17.11 2/2] net/nfp: replace strncpy by strlcpy

Yongseok Koh yskoh at mellanox.com
Thu Jan 3 09:26:27 CET 2019


GCC 8.1 error:

drivers/net/nfp/nfp_nspu.c: In function
‘nfp_nspu_set_bar_from_symbl.constprop’:
drivers/net/nfp/nfp_nspu.c:426:2: error: ‘strncpy’ output truncated
before terminating nul copying as many bytes from a string as its length
[-Werror=stringop-truncation]
  strncpy(sym_buf, symbl, strlen(symbl));
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fixes: dd63df2bfff3 ("net/nfp: add NSP symbol resolution command")
Cc: alejandro.lucero at netronome.com

Signed-off-by: Yongseok Koh <yskoh at mellanox.com>
---
 drivers/net/nfp/nfp_nspu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/nfp/nfp_nspu.c b/drivers/net/nfp/nfp_nspu.c
index f90898321..ac5bce3b1 100644
--- a/drivers/net/nfp/nfp_nspu.c
+++ b/drivers/net/nfp/nfp_nspu.c
@@ -9,6 +9,7 @@
 
 #include <rte_log.h>
 #include <rte_byteorder.h>
+#include <rte_string_fns.h>
 
 #include "nfp_nfpu.h"
 
@@ -423,7 +424,7 @@ nfp_nspu_set_bar_from_symbl(nspu_desc_t *desc, const char *symbl,
 	if (!sym_buf)
 		return -ENOMEM;
 
-	strncpy(sym_buf, symbl, strlen(symbl));
+	strlcpy(sym_buf, symbl, sizeof(sym_buf));
 	ret = nspu_command(desc, NSP_CMD_GET_SYMBOL, 1, 1, sym_buf,
 			   NFP_SYM_DESC_LEN, strlen(symbl));
 	if (ret) {
-- 
2.11.0



More information about the stable mailing list