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

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

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

Coverty issue: 272603
Fixes: 2f74ae28e23f ("examples/ip_pipeline: add tap object")

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

Comments

Bruce Richardson April 17, 2018, 2:59 p.m. UTC | #1
On Tue, Apr 17, 2018 at 02:17:19PM +0100, Jasvinder Singh wrote:
> The destination string may not have a null termination if
> the source string's length is equal to the sizeof(tap->name).
> 
> Fix by replacing strncpy with strlcpy that guarantees NULL-termination.
> 
> Coverty issue: 272603
> Fixes: 2f74ae28e23f ("examples/ip_pipeline: add tap object")
> 
> Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
> ---
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
  

Patch

diff --git a/examples/ip_pipeline/tap.c b/examples/ip_pipeline/tap.c
index 5b34032..a4e10fa 100644
--- a/examples/ip_pipeline/tap.c
+++ b/examples/ip_pipeline/tap.c
@@ -15,6 +15,8 @@ 
 #include <string.h>
 #include <unistd.h>
 
+#include <rte_string_fns.h>
+
 #include "tap.h"
 
 #define TAP_DEV                                            "/dev/net/tun"
@@ -85,7 +87,7 @@  tap_create(const char *name)
 		return NULL;
 
 	/* Node fill in */
-	strncpy(tap->name, name, sizeof(tap->name));
+	strlcpy(tap->name, name, sizeof(tap->name));
 	tap->fd = fd;
 
 	/* Node add to list */