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

Message ID 20180419110125.7759-1-kevin.laatz@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

Kevin Laatz April 19, 2018, 11:01 a.m. UTC
  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")
Cc: jasvinder.singh@intel.com

Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
---
 examples/ip_pipeline/mempool.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Jasvinder Singh April 19, 2018, 3:34 p.m. UTC | #1
> -----Original Message-----
> From: Laatz, Kevin
> Sent: Thursday, April 19, 2018 12:01 PM
> To: dev@dpdk.org
> Cc: Dumitrescu, Cristian <cristian.dumitrescu@intel.com>; Laatz, Kevin
> <kevin.laatz@intel.com>; Singh, Jasvinder <jasvinder.singh@intel.com>
> 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")
> Cc: jasvinder.singh@intel.com
> 
> Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
> ---
>  examples/ip_pipeline/mempool.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/examples/ip_pipeline/mempool.c
> b/examples/ip_pipeline/mempool.c index 33b9243..f5d2a7d 100644
> --- a/examples/ip_pipeline/mempool.c
> +++ b/examples/ip_pipeline/mempool.c
> @@ -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;
> 
> --
> 2.9.5

Reviewed-by: Jasvinder Singh <jasvinder.singh@intel.com>
  

Patch

diff --git a/examples/ip_pipeline/mempool.c b/examples/ip_pipeline/mempool.c
index 33b9243..f5d2a7d 100644
--- a/examples/ip_pipeline/mempool.c
+++ b/examples/ip_pipeline/mempool.c
@@ -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;