DPDK patches and discussions
 help / color / mirror / Atom feed
From: Andy Green <andy@warmcat.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v2 06/18] drivers/net/nfp/nfpcore: fix off-by-one and no NUL on strncpy use
Date: Wed, 09 May 2018 09:31:20 +0800	[thread overview]
Message-ID: <152582948090.6809.17293544631396610744.stgit@localhost.localdomain> (raw)
In-Reply-To: <152582834896.6809.14521072557832633661.stgit@localhost.localdomain>

/home/agreen/projects/dpdk/drivers/net/nfp/nfpcore/nfp_resource.c:
76:2:error: ‘strncpy’ output may be truncated copying 8 bytes from
a string of length 8 [-Werror=stringop-truncation]
  strncpy(name_pad, res->name, sizeof(name_pad));

Signed-off-by: Andy Green <andy@warmcat.com>
---
 drivers/net/nfp/nfpcore/nfp_resource.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c
index e1df2b2e1..a165b93df 100644
--- a/drivers/net/nfp/nfpcore/nfp_resource.c
+++ b/drivers/net/nfp/nfpcore/nfp_resource.c
@@ -7,6 +7,8 @@
 #include <time.h>
 #include <endian.h>
 
+#include <rte_string_fns.h>
+
 #include "nfp_cpp.h"
 #include "nfp6000/nfp6000.h"
 #include "nfp_resource.h"
@@ -65,15 +67,15 @@ struct nfp_resource {
 static int
 nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res)
 {
-	char name_pad[NFP_RESOURCE_ENTRY_NAME_SZ] = {};
+	char name_pad[NFP_RESOURCE_ENTRY_NAME_SZ + 2];
 	struct nfp_resource_entry entry;
 	uint32_t cpp_id, key;
 	int ret, i;
 
 	cpp_id = NFP_CPP_ID(NFP_RESOURCE_TBL_TARGET, 3, 0);  /* Atomic read */
 
-	memset(name_pad, 0, NFP_RESOURCE_ENTRY_NAME_SZ);
-	strncpy(name_pad, res->name, sizeof(name_pad));
+	memset(name_pad, 0, sizeof(name_pad));
+	strlcpy(name_pad, res->name, sizeof(name_pad));
 
 	/* Search for a matching entry */
 	if (!memcmp(name_pad, NFP_RESOURCE_TBL_NAME "\0\0\0\0\0\0\0\0", 8)) {

  parent reply	other threads:[~2018-05-09  2:36 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-09  1:30 [dpdk-dev] [PATCH v2 00/18] Fix build on gcc8 and various bugs Andy Green
2018-05-09  1:30 ` [dpdk-dev] [PATCH v2 01/18] lib/libtre_table: workaround hash function cast error Andy Green
2018-05-09  1:31 ` [dpdk-dev] [PATCH v2 02/18] drivers/bus/pci: fix strncpy dangerous code Andy Green
2018-05-09  1:31 ` [dpdk-dev] [PATCH v2 03/18] drivers/bus/dpaa: fix inconsistent struct alignment Andy Green
2018-05-09  8:06   ` Hemant Agrawal
2018-05-09  1:31 ` [dpdk-dev] [PATCH v2 04/18] drivers/net/axgbe: fix broken eeprom string comp Andy Green
2018-05-09  1:31 ` [dpdk-dev] [PATCH v2 05/18] drivers/net/nfp/nfpcore: fix strncpy misuse Andy Green
2018-05-09  9:49   ` Alejandro Lucero
2018-05-09  1:31 ` Andy Green [this message]
2018-05-09  9:53   ` [dpdk-dev] [PATCH v2 06/18] drivers/net/nfp/nfpcore: fix off-by-one and no NUL on strncpy use Alejandro Lucero
2018-05-09  1:31 ` [dpdk-dev] [PATCH v2 07/18] drivers/net/nfp: don't memcpy out of source range Andy Green
2018-05-09  9:54   ` Alejandro Lucero
2018-05-09  1:31 ` [dpdk-dev] [PATCH v2 08/18] drivers/net/nfp: fix buffer overflow in fw_name Andy Green
2018-05-09 10:04   ` Alejandro Lucero
2018-05-09  1:31 ` [dpdk-dev] [PATCH v2 09/18] drivers/net/qede: fix strncpy constant and NUL Andy Green
2018-05-09  1:31 ` [dpdk-dev] [PATCH v2 10/18] drivers/net/qede: fix broken strncpy Andy Green
2018-05-09  1:31 ` [dpdk-dev] [PATCH v2 11/18] drivers/net/sfc: fix strncpy length Andy Green
2018-05-09  1:31 ` [dpdk-dev] [PATCH v2 12/18] drivers/net/sfc: fix strncpy size and NUL Andy Green
2018-05-09  1:31 ` [dpdk-dev] [PATCH v2 13/18] drivers/net/vdev: readlink inputs cannot be aliased Andy Green
2018-05-09 15:33   ` Stephen Hemminger
2018-05-09  1:32 ` [dpdk-dev] [PATCH v2 14/18] drivers/net/vdev: fix 3 x strncpy misuse Andy Green
2018-05-09  1:32 ` [dpdk-dev] [PATCH v2 15/18] app/test-pmd: can't find include Andy Green
2018-05-09  1:32 ` [dpdk-dev] [PATCH v2 16/18] app/proc-info: fix sprintf overrun bug Andy Green
2018-05-09  1:32 ` [dpdk-dev] [PATCH v2 17/18] app/test-bbdev: test-bbdev: strcpy ok for allocated string Andy Green
2018-05-09  1:32 ` [dpdk-dev] [PATCH v2 18/18] app/test-bbdev: " Andy Green

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=152582948090.6809.17293544631396610744.stgit@localhost.localdomain \
    --to=andy@warmcat.com \
    --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).