From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.warmcat.com (mail.warmcat.com [163.172.24.82]) by dpdk.org (Postfix) with ESMTP id A533E1BD92 for ; Fri, 11 May 2018 03:45:54 +0200 (CEST) From: Andy Green To: dev@dpdk.org Date: Fri, 11 May 2018 09:45:50 +0800 Message-ID: <152600315096.53146.4309625575083492451.stgit@localhost.localdomain> In-Reply-To: <152600304856.53146.9681482138854493833.stgit@localhost.localdomain> References: <152600304856.53146.9681482138854493833.stgit@localhost.localdomain> User-Agent: StGit/unknown-version Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v4 07/18] net/nfp/nfpcore: off-by-one and no NUL on strncpy use 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: , X-List-Received-Date: Fri, 11 May 2018 01:45:54 -0000 /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 --- drivers/net/nfp/nfpcore/nfp_resource.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index e1df2b2e1..dd41fa4de 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -7,6 +7,8 @@ #include #include +#include + #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 +