[dpdk-dev] examples/ip_pipeline: fix buffer not null terminated

Message ID 20180416165708.120699-1-jasvinder.singh@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Cristian Dumitrescu
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Jasvinder Singh April 16, 2018, 4:57 p.m. UTC
  The destination string may not have a null termination if
the source string's length is equal to the sizeof(link->name).

Fix by replacing strncpy with strlcpy that guarantees NULL-termination.

Coverty issue: 272594
Fixes: 133c2c6565d6 ("examples/ip_pipeline: add link object")

Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
---
 examples/ip_pipeline/link.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Patch

diff --git a/examples/ip_pipeline/link.c b/examples/ip_pipeline/link.c
index 26ff41b..b8a431f 100644
--- a/examples/ip_pipeline/link.c
+++ b/examples/ip_pipeline/link.c
@@ -6,6 +6,7 @@ 
 #include <string.h>
 
 #include <rte_ethdev.h>
+#include <rte_string_fns.h>
 
 #include "link.h"
 #include "mempool.h"
@@ -236,7 +237,7 @@  link_create(const char *name, struct link_params *params)
 	}
 
 	/* Node fill in */
-	strncpy(link->name, name, sizeof(link->name));
+	strlcpy(link->name, name, sizeof(link->name));
 	link->port_id = port_id;
 	link->n_rxq = params->rx.n_queues;
 	link->n_txq = params->tx.n_queues;