[2/8] net/nfp: fix string overflow

Message ID 20240314070536.3169210-3-chaoyong.he@corigine.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series fix some coverity issues |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Chaoyong He March 14, 2024, 7:05 a.m. UTC
  CI found in the logic of 'nfp_sync_pci_inner_handle_alloc()', use
'strcpy()' may cause string overflow, fix it by use 'rte_strlcpy()'.

Coverity issue: 414937
Fixes: 6b4273a03779 ("net/nfp: add synchronization module")
Cc: long.wu@corigine.com
Cc: stable@dpdk.org

Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
---
 drivers/net/nfp/nfpcore/nfp_sync.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Patch

diff --git a/drivers/net/nfp/nfpcore/nfp_sync.c b/drivers/net/nfp/nfpcore/nfp_sync.c
index 8bc38d6585..686cdf8eb1 100644
--- a/drivers/net/nfp/nfpcore/nfp_sync.c
+++ b/drivers/net/nfp/nfpcore/nfp_sync.c
@@ -9,6 +9,7 @@ 
 #include <rte_malloc.h>
 #include <rte_memzone.h>
 #include <rte_spinlock.h>
+#include <rte_string_fns.h>
 
 #include "nfp_logs.h"
 
@@ -266,7 +267,7 @@  nfp_sync_pci_inner_handle_alloc(struct nfp_sync *sync,
 	for (i = 0; i < NFP_SYNC_PCI_MAX; i++) {
 		if (strlen(sync->pci[i].pci_name) == 0) {
 			pci_avail_id = i;
-			strcpy(sync->pci[pci_avail_id].pci_name, pci_name);
+			rte_strlcpy(sync->pci[pci_avail_id].pci_name, pci_name, PCI_PRI_STR_SIZE);
 			goto common_alloc;
 		}
 	}