summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Green <andy@warmcat.com>2018-05-14 13:00:27 +0800
committerFerruh Yigit <ferruh.yigit@intel.com>2018-05-14 23:32:23 +0200
commit62280b7819d24643e70a1428191288133d3d7235 (patch)
tree77c54c5a888d238c9b3081be2b0fb7e392c0c904
parent01077fa9ac9c320e84b85f2965056b926401b316 (diff)
downloaddpdk-62280b7819d24643e70a1428191288133d3d7235.zip
dpdk-62280b7819d24643e70a1428191288133d3d7235.tar.gz
dpdk-62280b7819d24643e70a1428191288133d3d7235.tar.xz
net/nfp: fix off-by-one and no nul on strncpy use
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)); Fixes: c7e9729da6b5 ("net/nfp: support CPP") Signed-off-by: Andy Green <andy@warmcat.com> Acked-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
-rw-r--r--drivers/net/nfp/nfpcore/nfp_resource.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c
index e1df2b2..dd41fa4 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,22 +67,22 @@ 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)) {
printf("Grabbing device lock not supported\n");
return -EOPNOTSUPP;
}
- key = nfp_crc32_posix(name_pad, sizeof(name_pad));
+ key = nfp_crc32_posix(name_pad, NFP_RESOURCE_ENTRY_NAME_SZ);
for (i = 0; i < NFP_RESOURCE_TBL_ENTRIES; i++) {
uint64_t addr = NFP_RESOURCE_TBL_BASE +