Skip to contentSkip to conversation

examples/ip_pipeline: fixes uninitialized scalar variable

PATCH In review Reshma Pattan 2 participants 8 messages Apr 18, 2018 – Apr 19, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 examples/ip_pipeline: fixes uninitialized scalar variable

Using uninitialized value p.thread_id when calling kni_create. Initialize the kni_params object to 0.

Coverity issue: 272569

Fixes 9a408cc8ac ("examples/ip_pipeline: add KNI object")
---
 examples/ip_pipeline/cli.c | 1 +
 1 file changed, 1 insertion(+)
examples/ip_pipeline/cli.c +1 -0
index 199a31ff8..575e176c1 100644
@@ -651,6 +651,7 @@ cmd_kni(char **tokens,
 	char *name;
 	struct kni *kni;
 
+	memset(&p, 0, sizeof(p));
 	if ((n_tokens != 6) && (n_tokens != 8)) {
 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
 		return;
Signature · 1 line
2.14.3
#1 lore raw

PATCH 1/1 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")
---
 examples/ip_pipeline/kni.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
examples/ip_pipeline/kni.c +2 -1
index ed5f8942e..7e5ff0543 100644
@@ -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 */
Signature · 1 line
2.14.3
Reviewed-by on v1 1/1
#2 lore raw

Re: [PATCH] examples/ip_pipeline: fix buffer not null terminated

Quoted 46 lines

-----Original Message-----
From: Pattan, Reshma
Sent: Wednesday, April 18, 2018 5:58 PM
To: [email protected]
Cc: Singh, Jasvinder <[email protected]>; Pattan, Reshma <[email protected]>
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")
---
 examples/ip_pipeline/kni.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
examples/ip_pipeline/kni.c index renamed from examples/ip_pipeline/kni.c +0 -0

ed5f8942e..7e5ff0543 100644

examples/ip_pipeline/kni.c +2 -1
@@ -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;
 
Quoted 3 lines

/* Node add to list */
--
2.14.3

#3 lore raw

PATCH 1/1 examples/ip_pipipeline: fix resource leak

In reply to Reshma Pattan

Close tap device fd before returning upon failures.

Coverity issue: 272576

Fixes 2f74ae28e2 ("examples/ip_pipeline: add tap object")
---
 examples/ip_pipeline/tap.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
examples/ip_pipeline/tap.c +6 -3
index 5b3403218..a0f60867f 100644
@@ -76,14 +76,17 @@ tap_create(const char *name)
 	snprintf(ifr.ifr_name, IFNAMSIZ, "%s", name);
 
 	status = ioctl(fd, TUNSETIFF, (void *) &ifr);
-	if (status < 0)
+	if (status < 0) {
+		close(fd);
 		return NULL;
+	}
 
 	/* Node allocation */
 	tap = calloc(1, sizeof(struct tap));
-	if (tap == NULL)
+	if (tap == NULL) {
+		close(fd);
 		return NULL;
-
+	}
 	/* Node fill in */
 	strncpy(tap->name, name, sizeof(tap->name));
 	tap->fd = fd;
Signature · 1 line
2.14.3
Reviewed-by on v1 1/1
#4 lore raw

Re: [PATCH] examples/ip_pipipeline: fix resource leak

Quoted 47 lines

-----Original Message-----
From: Pattan, Reshma
Sent: Wednesday, April 18, 2018 5:58 PM
To: [email protected]
Cc: Singh, Jasvinder <[email protected]>; Pattan, Reshma <[email protected]>
Subject: [PATCH] examples/ip_pipipeline: fix resource leak

Close tap device fd before returning upon failures.

Coverity issue: 272576

Fixes 2f74ae28e2 ("examples/ip_pipeline: add tap object")
---
 examples/ip_pipeline/tap.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
examples/ip_pipeline/tap.c index renamed from examples/ip_pipeline/tap.c +0 -0

5b3403218..a0f60867f 100644

examples/ip_pipeline/tap.c +6 -4
@@ -76,14 +76,17 @@ tap_create(const char *name)
 	snprintf(ifr.ifr_name, IFNAMSIZ, "%s", name);
 
 	status = ioctl(fd, TUNSETIFF, (void *) &ifr);
-	if (status < 0)
+	if (status < 0) {
+		close(fd);
 		return NULL;
+	}
 
 	/* Node allocation */
 	tap = calloc(1, sizeof(struct tap));
-	if (tap == NULL)
+	if (tap == NULL) {
+		close(fd);
 		return NULL;
-
+	}
 	/* Node fill in */
 	strncpy(tap->name, name, sizeof(tap->name));
 	tap->fd = fd;
--
Quoted 1 line

2.14.3

#5 lore raw

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

In reply to Reshma Pattan

Copying source string of length equal to sizeof(profile->name) will not append the NULL in destination.

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

Coverity issue: 272580

Fixes 719374345c ("examples/ip_pipeline: add action profile objects")
---
 examples/ip_pipeline/action.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
examples/ip_pipeline/action.c +3 -1
index 77a04fe19..d2cd7286c 100644
@@ -6,6 +6,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <rte_string_fns.h>
+
 #include "action.h"
 #include "hash_func.h"
 
@@ -345,7 +347,7 @@ table_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.14.3
Reviewed-by on v1 1/1
#6 lore raw

Re: [PATCH] examples/ip_pipeline: fix buffer not null terminated

Quoted 48 lines

-----Original Message-----
From: Pattan, Reshma
Sent: Wednesday, April 18, 2018 5:58 PM
To: [email protected]
Cc: Singh, Jasvinder <[email protected]>; Pattan, Reshma <[email protected]>
Subject: [PATCH] examples/ip_pipeline: fix buffer not null terminated

Copying source string of length equal to sizeof(profile->name) will not append the NULL in destination.

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

Coverity issue: 272580

Fixes 719374345c ("examples/ip_pipeline: add action profile objects")
---
 examples/ip_pipeline/action.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
examples/ip_pipeline/action.c +3 -2
index 77a04fe19..d2cd7286c 100644
@@ -6,6 +6,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <rte_string_fns.h>
+
 #include "action.h"
 #include "hash_func.h"
 
@@ -345,7 +347,7 @@ table_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;
 
--
Quoted 1 line

2.14.3

Reviewed-by on v1 1/1
#7 lore raw
In reply to Reshma Pattan
Quoted 35 lines

-----Original Message-----
From: Pattan, Reshma
Sent: Wednesday, April 18, 2018 5:58 PM
To: [email protected]
Cc: Singh, Jasvinder <[email protected]>; Pattan, Reshma <[email protected]>
Subject: [PATCH] examples/ip_pipeline: fixes uninitialized scalar variable

Using uninitialized value p.thread_id when calling kni_create. Initialize the kni_params object to 0.

Coverity issue: 272569

Fixes 9a408cc8ac ("examples/ip_pipeline: add KNI object")
---
 examples/ip_pipeline/cli.c | 1 +
 1 file changed, 1 insertion(+)
examples/ip_pipeline/cli.c index renamed from examples/ip_pipeline/cli.c +0 -0

199a31ff8..575e176c1 100644

examples/ip_pipeline/cli.c +1 -1
@@ -651,6 +651,7 @@ cmd_kni(char **tokens,
 	char *name;
 	struct kni *kni;
 
+	memset(&p, 0, sizeof(p));
 	if ((n_tokens != 6) && (n_tokens != 8)) {
 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
 		return;
--
Quoted 1 line

2.14.3