Skip to contentSkip to conversation

examples/ip_pipeline: fix buffer not null terminated

PATCH Superseded Jasvinder Singh 3 participants 5 messages Apr 17, 2018 – May 8, 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 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")
---
 examples/ip_pipeline/pipeline.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
examples/ip_pipeline/pipeline.c +1 -1
index 76aa1d3..132f1a8 100644
@@ -129,7 +129,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;
Signature · 1 line
2.9.3
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Jasvinder Singh

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")

Does this need an include of rte_string_fns.h?

In terms of the change itself:

Quoted 20 lines
---
 examples/ip_pipeline/pipeline.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
examples/ip_pipeline/pipeline.c +1 -1
index 76aa1d3..132f1a8 100644
@@ -129,7 +129,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;
Signature · 1 line
2.9.3
#2 lore raw
Quoted 17 lines

-----Original Message-----
From: Richardson, Bruce
Sent: Tuesday, April 17, 2018 4:01 PM
To: Singh, Jasvinder <[email protected]>
Cc: [email protected]; Dumitrescu, Cristian <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] examples/ip_pipeline: fix buffer not null terminated

Quoted 8 lines · Jasvinder Singh

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")
Quoted 8 lines
Quoted 1 line

Does this need an include of rte_string_fns.h?

In terms of the change itself:

It got reference of rte_string_fns.h through other header files there. So build was ok, but I will send v2 with explicit include. Thanks.

#3 lore raw

PATCH v2 1/1 examples/ip_pipeline: fix buffer not null terminated

In reply to Jasvinder Singh

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")
---
 examples/ip_pipeline/pipeline.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
examples/ip_pipeline/pipeline.c +2 -1
index 76aa1d3..43fe867 100644
@@ -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;
Signature · 1 line
2.9.3
Acked-by on v2 1/1 Applied
#4 lore raw
Quoted 46 lines

-----Original Message-----
From: Singh, Jasvinder
Sent: Tuesday, April 17, 2018 5:40 PM
To: [email protected]
Cc: Dumitrescu, Cristian <[email protected]>; Richardson, Bruce <[email protected]>
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")
---
 examples/ip_pipeline/pipeline.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
examples/ip_pipeline/pipeline.c +2 -1
index 76aa1d3..43fe867 100644
@@ -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;
Quoted 3 lines

pipeline->n_ports_out = 0;
--
2.9.3

Applied to next-pipeline tree, thanks!