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

Message ID 20180417163953.72821-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 17, 2018, 4:39 p.m. UTC
  The destination string may not have a null termination if
the source string's length is equal to the sizeof(pipeline->name).

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

Coverty issue: 272606
Fixes: d75c371e9b46 ("examples/ip_pipeline: add pipeline object")

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

Comments

Cristian Dumitrescu May 8, 2018, 2:29 p.m. UTC | #1
> -----Original Message-----
> From: Singh, Jasvinder
> Sent: Tuesday, April 17, 2018 5:40 PM
> To: dev@dpdk.org
> Cc: Dumitrescu, Cristian <cristian.dumitrescu@intel.com>; Richardson, Bruce
> <bruce.richardson@intel.com>
> Subject: [PATCH v2] examples/ip_pipeline: fix buffer not null terminated
> 
> The destination string may not have a null termination if
> the source string's length is equal to the sizeof(pipeline->name).
> 
> Fix by replacing strncpy with strlcpy that guarantees NULL-termination.
> 
> Coverty issue: 272606
> Fixes: d75c371e9b46 ("examples/ip_pipeline: add pipeline object")
> 
> Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
>  examples/ip_pipeline/pipeline.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/examples/ip_pipeline/pipeline.c
> b/examples/ip_pipeline/pipeline.c
> index 76aa1d3..43fe867 100644
> --- a/examples/ip_pipeline/pipeline.c
> +++ b/examples/ip_pipeline/pipeline.c
> @@ -9,6 +9,7 @@
>  #include <rte_ip.h>
>  #include <rte_tcp.h>
> 
> +#include <rte_string_fns.h>
>  #include <rte_port_ethdev.h>
>  #ifdef RTE_LIBRTE_KNI
>  #include <rte_port_kni.h>
> @@ -129,7 +130,7 @@ pipeline_create(const char *name, struct
> pipeline_params *params)
>  	}
> 
>  	/* Node fill in */
> -	strncpy(pipeline->name, name, sizeof(pipeline->name));
> +	strlcpy(pipeline->name, name, sizeof(pipeline->name));
>  	pipeline->p = p;
>  	pipeline->n_ports_in = 0;
>  	pipeline->n_ports_out = 0;
> --
> 2.9.3
Acked-by: Cristian.Dumitrescu <cristian.dumitrescu@intel.com>

Applied to next-pipeline tree, thanks!
  

Patch

diff --git a/examples/ip_pipeline/pipeline.c b/examples/ip_pipeline/pipeline.c
index 76aa1d3..43fe867 100644
--- a/examples/ip_pipeline/pipeline.c
+++ b/examples/ip_pipeline/pipeline.c
@@ -9,6 +9,7 @@ 
 #include <rte_ip.h>
 #include <rte_tcp.h>
 
+#include <rte_string_fns.h>
 #include <rte_port_ethdev.h>
 #ifdef RTE_LIBRTE_KNI
 #include <rte_port_kni.h>
@@ -129,7 +130,7 @@  pipeline_create(const char *name, struct pipeline_params *params)
 	}
 
 	/* Node fill in */
-	strncpy(pipeline->name, name, sizeof(pipeline->name));
+	strlcpy(pipeline->name, name, sizeof(pipeline->name));
 	pipeline->p = p;
 	pipeline->n_ports_in = 0;
 	pipeline->n_ports_out = 0;