Skip to contentSkip to conversation

examples/ip_pipeline: fix buffer not null terminated

PATCH Applied Fan Zhang 3 participants 7 messages Apr 16, 2018 – May 9, 2018

lore
Share & tools
lore

Fan Zhang

author
#0 lore raw

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

Coverity issue: 272572

Fixes 719374345cee ("examples/ip_pipeline: add action profile objects")
---
 examples/ip_pipeline/action.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
examples/ip_pipeline/action.c +1 -1
index 77a04fe19..91011ebe8 100644
@@ -133,7 +133,7 @@ port_in_action_profile_create(const char *name,
 	}
 
 	/* Node fill in */
-	strncpy(profile->name, name, sizeof(profile->name));
+	strncpy(profile->name, name, sizeof(profile->name) - 1);
 	memcpy(&profile->params, params, sizeof(*params));
 	profile->ap = ap;
 
Signature · 1 line
2.13.6
#1 lore raw
Quoted 13 lines · Fan Zhang

Coverity issue: 272572

Fixes 719374345cee ("examples/ip_pipeline: add action profile objects")
---
 examples/ip_pipeline/action.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
examples/ip_pipeline/action.c +0 -0
index 77a04fe19..91011ebe8 100644

examples/ip_pipeline/action.c port_in_action_profile_create(const char *name, · line 138

Quoted 7 lines
examples/ip_pipeline/action.c +1 -1
@@ -133,7 +133,7 @@ port_in_action_profile_create(const char *name,
 	}
 
 	/* Node fill in */
-	strncpy(profile->name, name, sizeof(profile->name));
+	strncpy(profile->name, name, sizeof(profile->name) - 1);
 	memcpy(&profile->params, params, sizeof(*params));
 	profile->ap = ap;

No, this still doesn't null terminate, and is a perfect example of why we should never use strncpy! Use strlcpy instead.

author
#2 lore raw

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

In reply to Fan Zhang

Coverity issue: 272572

Fixes 719374345cee ("examples/ip_pipeline: add action profile objects")

---
v2:
- use more generic strlcpy approach

 examples/ip_pipeline/action.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
examples/ip_pipeline/action.c +3 -1
index 77a04fe19..1203bb892 100644
@@ -6,6 +6,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <rte_string_fns.h>
+
 #include "action.h"
 #include "hash_func.h"
 
@@ -133,7 +135,7 @@ port_in_action_profile_create(const char *name,
 	}
 
 	/* Node fill in */
-	strncpy(profile->name, name, sizeof(profile->name));
+	strlcpy(profile->name, name, sizeof(profile->name));
 	memcpy(&profile->params, params, sizeof(*params));
 	profile->ap = ap;
 
Signature · 1 line
2.13.6
Acked-by on v2 1/1
#3 lore raw
Quoted 26 lines · Fan Zhang

Coverity issue: 272572

Fixes 719374345cee ("examples/ip_pipeline: add action profile objects")

---
v2:
- use more generic strlcpy approach

 examples/ip_pipeline/action.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
examples/ip_pipeline/action.c +2 -0
index 77a04fe19..1203bb892 100644
@@ -6,6 +6,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <rte_string_fns.h>
+
 #include "action.h"
 #include "hash_func.h"
 

examples/ip_pipeline/action.c port_in_action_profile_create(const char *name, · line 141

Quoted 8 lines
examples/ip_pipeline/action.c +1 -1
@@ -133,7 +135,7 @@ port_in_action_profile_create(const char *name,
 	}
 
 	/* Node fill in */
-	strncpy(profile->name, name, sizeof(profile->name));
+	strlcpy(profile->name, name, sizeof(profile->name));
 	memcpy(&profile->params, params, sizeof(*params));
 	profile->ap = ap;
 
Acked-by on v1 1/1 Applied
#4 lore raw
In reply to Fan Zhang
Quoted 32 lines

-----Original Message-----
From: Zhang, Roy Fan
Sent: Monday, April 16, 2018 12:03 PM
To: [email protected]
Cc: Dumitrescu, Cristian <[email protected]>; Singh, Jasvinder <[email protected]>
Subject: [PATCH] examples/ip_pipeline: fix buffer not null terminated

Coverity issue: 272572

Fixes 719374345cee ("examples/ip_pipeline: add action profile objects")
---
 examples/ip_pipeline/action.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
examples/ip_pipeline/action.c +1 -2
index 77a04fe19..91011ebe8 100644
@@ -133,7 +133,7 @@ port_in_action_profile_create(const char *name,
 	}
 
 	/* Node fill in */
-	strncpy(profile->name, name, sizeof(profile->name));
+	strncpy(profile->name, name, sizeof(profile->name) - 1);
 	memcpy(&profile->params, params, sizeof(*params));
 	profile->ap = ap;
 
--
Quoted 1 line

2.13.6

Applied to next-pipeline tree, thanks!

#5 lore raw
Quoted 31 lines · Cristian
Quoted 31 lines

-----Original Message-----
From: Zhang, Roy Fan
Sent: Monday, April 16, 2018 12:03 PM
To: [email protected]
Cc: Dumitrescu, Cristian <[email protected]>; Singh, Jasvinder <[email protected]>
Subject: [PATCH] examples/ip_pipeline: fix buffer not null terminated

Coverity issue: 272572

Fixes 719374345cee ("examples/ip_pipeline: add action profile objects")
---
 examples/ip_pipeline/action.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
examples/ip_pipeline/action.c +1 -1
index 77a04fe19..91011ebe8 100644
@@ -133,7 +133,7 @@ port_in_action_profile_create(const char *name,
 	}
 
 	/* Node fill in */
-	strncpy(profile->name, name, sizeof(profile->name));
+	strncpy(profile->name, name, sizeof(profile->name) - 1);
 	memcpy(&profile->params, params, sizeof(*params));
 	profile->ap = ap;
 
Quoted 6 lines
Quoted 2 lines

--
2.13.6

Applied to next-pipeline tree, thanks!

This is not a correct fix, and the code is still broken. However, I see that you have actually applied the correct v2 patch to the tree, so no big deal. It's probably best to reply to the correct patch confirming it's applied, though.

/Bruce

#6 lore raw
Quoted 51 lines

-----Original Message-----
From: Richardson, Bruce
Sent: Tuesday, May 8, 2018 8:51 PM
To: Dumitrescu, Cristian <[email protected]>
Cc: Zhang, Roy Fan <[email protected]>; [email protected]; Singh, Jasvinder <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] examples/ip_pipeline: fix buffer not null terminated

Quoted 7 lines · Cristian
Quoted 7 lines

-----Original Message-----
From: Zhang, Roy Fan
Sent: Monday, April 16, 2018 12:03 PM
To: [email protected]
Cc: Dumitrescu, Cristian <[email protected]>; Singh,

Jasvinder

Quoted 6 lines
Quoted 6 lines

<[email protected]>
Subject: [PATCH] examples/ip_pipeline: fix buffer not null terminated

Coverity issue: 272572

Fixes 719374345cee ("examples/ip_pipeline: add action profile objects")
Quoted 6 lines

Review

Quoted 6 lines
---
 examples/ip_pipeline/action.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
(quoted diff) +0 -0

b/examples/ip_pipeline/action.c

Quoted 4 lines

examples/ip_pipeline/action.c port_in_action_profile_create(const char

Quoted 4 lines

index 77a04fe19..91011ebe8 100644

examples/ip_pipeline/action.c +0 -0
@@ -133,7 +133,7 @@ port_in_action_profile_create(const char

*name,

Quoted 13 lines
Quoted 10 lines
examples/ip_pipeline/action.c +1 -2
 	}
 
 	/* Node fill in */
-	strncpy(profile->name, name, sizeof(profile->name));
+	strncpy(profile->name, name, sizeof(profile->name) - 1);
 	memcpy(&profile->params, params, sizeof(*params));
 	profile->ap = ap;
 
--

2.13.6

Quoted 8 lines
Quoted 1 line

Applied to next-pipeline tree, thanks!

This is not a correct fix, and the code is still broken. However, I see that you have actually applied the correct v2 patch to the tree, so no big deal. It's probably best to reply to the correct patch confirming it's applied, though.

/Bruce

Yes, the right patch (v2) was applied, the wrong email was replied.