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(tmgr_port->name).

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

Coverity issue: 272592

Fixes 25961ff3bcb9 ("examples/ip_pipeline: add traffic manager object")
---
 examples/ip_pipeline/tmgr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
examples/ip_pipeline/tmgr.c +3 -1
index b46ca96..40cbf1d 100644
@@ -4,6 +4,8 @@
 
 #include <stdlib.h>
 
+#include <rte_string_fns.h>
+
 #include "tmgr.h"
 
 static struct rte_sched_subport_params
@@ -148,7 +150,7 @@ tmgr_port_create(const char *name, struct tmgr_port_params *params)
 	}
 
 	/* Node fill in */
-	strncpy(tmgr_port->name, name, sizeof(tmgr_port->name));
+	strlcpy(tmgr_port->name, name, sizeof(tmgr_port->name));
 	tmgr_port->s = s;
 	tmgr_port->n_subports_per_port = params->n_subports_per_port;
 	tmgr_port->n_pipes_per_subport = params->n_pipes_per_subport;
Signature · 1 line
2.9.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 47 lines

-----Original Message-----
From: Laatz, Kevin
Sent: Thursday, April 19, 2018 12:03 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(tmgr_port->name).

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

Coverity issue: 272592

Fixes 25961ff3bcb9 ("examples/ip_pipeline: add traffic manager object")
---
 examples/ip_pipeline/tmgr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
examples/ip_pipeline/tmgr.c index renamed from examples/ip_pipeline/tmgr.c +0 -0

b46ca96..40cbf1d 100644

examples/ip_pipeline/tmgr.c +3 -1
@@ -4,6 +4,8 @@
 
 #include <stdlib.h>
 
+#include <rte_string_fns.h>
+
 #include "tmgr.h"
 
 static struct rte_sched_subport_params
@@ -148,7 +150,7 @@ tmgr_port_create(const char *name, struct
 tmgr_port_params *params)
 	}
 
 	/* Node fill in */
-	strncpy(tmgr_port->name, name, sizeof(tmgr_port->name));
+	strlcpy(tmgr_port->name, name, sizeof(tmgr_port->name));
 	tmgr_port->s = s;
 	tmgr_port->n_subports_per_port = params->n_subports_per_port;
Quoted 3 lines

tmgr_port->n_pipes_per_subport = params->n_pipes_per_subport;
--
2.9.5