Skip to contentSkip to conversation

examples/ip_pipeline: fix buffer not null terminated

PATCH In review Kevin Laatz 2 participants 2 messages Apr 19, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 examples/ip_pipeline: fix buffer not null terminated

The destination string may not have a NULL termination if the source's string is equal to the sizeof(mempool->name).

Using strlcpy in place of strncpy fixes this issue as strlcpy guarantees NULL termination.

Coverity issue: 272588

Fixes 6bfe74f8c93e ("examples/ip_pipeline: add mempool object")
---
 examples/ip_pipeline/mempool.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
examples/ip_pipeline/mempool.c +2 -1
index 33b9243..f5d2a7d 100644
@@ -6,6 +6,7 @@
 #include <string.h>
 
 #include <rte_mbuf.h>
+#include <rte_string_fns.h>
 
 #include "mempool.h"
 
@@ -70,7 +71,7 @@ mempool_create(const char *name, struct mempool_params *params)
 	}
 
 	/* Node fill in */
-	strncpy(mempool->name, name, sizeof(mempool->name));
+	strlcpy(mempool->name, name, sizeof(mempool->name));
 	mempool->m = m;
 	mempool->buffer_size = params->buffer_size;
 
Signature · 1 line
2.9.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 48 lines

-----Original Message-----
From: Laatz, Kevin
Sent: Thursday, April 19, 2018 12:01 PM
To: [email protected]
Cc: Dumitrescu, Cristian <[email protected]>; Laatz, Kevin <[email protected]>; Singh, Jasvinder <[email protected]>
Subject: [PATCH] examples/ip_pipeline: fix buffer not null terminated

The destination string may not have a NULL termination if the source's string is equal to the sizeof(mempool->name).

Using strlcpy in place of strncpy fixes this issue as strlcpy guarantees NULL termination.

Coverity issue: 272588

Fixes 6bfe74f8c93e ("examples/ip_pipeline: add mempool object")
---
 examples/ip_pipeline/mempool.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/examples/ip_pipeline/mempool.c index 33b9243..f5d2a7d 100644

examples/ip_pipeline/mempool.c +2 -2
@@ -6,6 +6,7 @@
 #include <string.h>
 
 #include <rte_mbuf.h>
+#include <rte_string_fns.h>
 
 #include "mempool.h"
 
@@ -70,7 +71,7 @@ mempool_create(const char *name, struct
 mempool_params *params)
 	}
 
 	/* Node fill in */
-	strncpy(mempool->name, name, sizeof(mempool->name));
+	strlcpy(mempool->name, name, sizeof(mempool->name));
 	mempool->m = m;
 	mempool->buffer_size = params->buffer_size;
 
--
Quoted 1 line

2.9.5