diff mbox

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

Message ID 1524070690-12000-2-git-send-email-reshma.pattan@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Cristian Dumitrescu
Headers show

Checks

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

Commit Message

Pattan, Reshma April 18, 2018, 4:58 p.m. UTC
Copying source string of length equal to sizeof(kni->name)
will not append the NULL to destination string.

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

Coverity issue: 272562
Fixes: 9a408cc8ac ("examples/ip_pipeline: add KNI object")
CC: jasvinder.singh@intel.com

Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
---
 examples/ip_pipeline/kni.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Singh, Jasvinder April 19, 2018, 8:36 a.m. UTC | #1
> -----Original Message-----
> From: Pattan, Reshma
> Sent: Wednesday, April 18, 2018 5:58 PM
> To: dev@dpdk.org
> Cc: Singh, Jasvinder <jasvinder.singh@intel.com>; Pattan, Reshma
> <reshma.pattan@intel.com>
> Subject: [PATCH] examples/ip_pipeline: fix buffer not null terminated
> 
> Copying source string of length equal to sizeof(kni->name) will not append the
> NULL to destination string.
> 
> Using strlcpy in place of strncpy fixes this issue as strlcpy guarantees NULL
> termination.
> 
> Coverity issue: 272562
> Fixes: 9a408cc8ac ("examples/ip_pipeline: add KNI object")
> CC: jasvinder.singh@intel.com
> 
> Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
> ---
>  examples/ip_pipeline/kni.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/examples/ip_pipeline/kni.c b/examples/ip_pipeline/kni.c index
> ed5f8942e..7e5ff0543 100644
> --- a/examples/ip_pipeline/kni.c
> +++ b/examples/ip_pipeline/kni.c
> @@ -7,6 +7,7 @@
> 
>  #include <rte_ethdev.h>
>  #include <rte_bus_pci.h>
> +#include <rte_string_fns.h>
> 
>  #include "kni.h"
>  #include "mempool.h"
> @@ -153,7 +154,7 @@ kni_create(const char *name, struct kni_params
> *params)
>  		return NULL;
> 
>  	/* Node fill in */
> -	strncpy(kni->name, name, sizeof(kni->name));
> +	strlcpy(kni->name, name, sizeof(kni->name));
>  	kni->k = k;
> 
>  	/* Node add to list */
> --
> 2.14.3

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

Patch

diff --git a/examples/ip_pipeline/kni.c b/examples/ip_pipeline/kni.c
index ed5f8942e..7e5ff0543 100644
--- a/examples/ip_pipeline/kni.c
+++ b/examples/ip_pipeline/kni.c
@@ -7,6 +7,7 @@ 
 
 #include <rte_ethdev.h>
 #include <rte_bus_pci.h>
+#include <rte_string_fns.h>
 
 #include "kni.h"
 #include "mempool.h"
@@ -153,7 +154,7 @@  kni_create(const char *name, struct kni_params *params)
 		return NULL;
 
 	/* Node fill in */
-	strncpy(kni->name, name, sizeof(kni->name));
+	strlcpy(kni->name, name, sizeof(kni->name));
 	kni->k = k;
 
 	/* Node add to list */