Skip to contentSkip to conversation

examples/vhost: fix string split error handling issue

PATCH Superseded Cheng Jiang 2 participants 6 messages Nov 6, 2020 – Nov 13, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 examples/vhost: fix string split error handling issue

Add checking return value of string split function to fix the coverity issue.

Fixes 3a04ecb21420 ("examples/vhost: add async vhost args parsing")

Coverity issue: 363739

---
 examples/vhost/ioat.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
examples/vhost/ioat.c +8 -3
index b2c74f6537..04806c02d7 100644
@@ -54,9 +54,14 @@ open_ioat(const char *value)
 	}
 	args_nr = rte_strsplit(substr, strlen(substr),
 			dma_arg, MAX_VHOST_DEVICE, ',');
-	do {
+	while (i < args_nr) {
 		char *arg_temp = dma_arg[i];
-		rte_strsplit(arg_temp, strlen(arg_temp), ptrs, 2, '@');
+		uint8_t sub_nr;
+		sub_nr = rte_strsplit(arg_temp, strlen(arg_temp), ptrs, 2, '@');
+		if (sub_nr != 2) {
+			ret = -1;
+			goto out;
+		}
 
 		start = strstr(ptrs[0], "txd");
 		if (start == NULL) {
@@ -105,7 +110,7 @@ open_ioat(const char *value)
 
 		dma_info->nr++;
 		i++;
-	} while (i < args_nr);
+	}
 out:
 	free(input);
 	return ret;
Signature · 1 line
2.29.2
#1 lore raw
Quoted 16 lines · Cheng Jiang

Add checking return value of string split function to fix the coverity issue.

Fixes 3a04ecb21420 ("examples/vhost: add async vhost args parsing")

Coverity issue: 363739

---
 examples/vhost/ioat.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
examples/vhost/ioat.c +0 -0
index b2c74f6537..04806c02d7 100644

examples/vhost/ioat.c open_ioat(const char *value) · line 56

Quoted 3 lines
examples/vhost/ioat.c +0 -0
@@ -54,9 +54,14 @@ open_ioat(const char *value)
 	}
 	args_nr = rte_strsplit(substr, strlen(substr),
 			dma_arg, MAX_VHOST_DEVICE, ',');

I think you should check args_nr > 0 explicitly, and maybe even args_nr

Quoted 26 lines

= 0. And then propagate the error if condition is met.

examples/vhost/ioat.c +8 -3
-	do {
+	while (i < args_nr) {
 		char *arg_temp = dma_arg[i];
-		rte_strsplit(arg_temp, strlen(arg_temp), ptrs, 2, '@');
+		uint8_t sub_nr;
+		sub_nr = rte_strsplit(arg_temp, strlen(arg_temp), ptrs, 2, '@');
+		if (sub_nr != 2) {
+			ret = -1;
+			goto out;
+		}
 
 		start = strstr(ptrs[0], "txd");
 		if (start == NULL) {
@@ -105,7 +110,7 @@ open_ioat(const char *value)
 
 		dma_info->nr++;
 		i++;
-	} while (i < args_nr);
+	}
 out:
 	free(input);
 	return ret;
#2 lore raw

Hi,

Quoted 23 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, November 10, 2020 5:35 PM
To: Jiang, Cheng1 <[email protected]>; Xia, Chenbo <[email protected]>
Cc: [email protected]; Fu, Patrick <[email protected]>; Yang, YvonneX <[email protected]>
Subject: Re: [PATCH v1] examples/vhost: fix string split error handling issue

Quoted 11 lines · Cheng Jiang

Add checking return value of string split function to fix the coverity issue.

Fixes 3a04ecb21420 ("examples/vhost: add async vhost args parsing")

Coverity issue: 363739

---
 examples/vhost/ioat.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
Quoted 12 lines

examples/vhost/ioat.c open_ioat(const char *value) · line 56

Quoted 8 lines
examples/vhost/ioat.c index renamed from examples/vhost/ioat.c +0 -0

b2c74f6537..04806c02d7 100644

examples/vhost/ioat.c +0 -0
@@ -54,9 +54,14 @@ open_ioat(const char *value)
 	}
 	args_nr = rte_strsplit(substr, strlen(substr),
 			dma_arg, MAX_VHOST_DEVICE, ',');

I think you should check args_nr > 0 explicitly, and maybe even args_nr

Quoted 1 line

= 0. And then propagate the error if condition is met.

Sure, I'll fix it in the next version.

Thanks,
Cheng

Quoted 25 lines

examples/vhost/ioat.c open_ioat(const char *value)

Quoted 7 lines
examples/vhost/ioat.c +3 -2
-	do {
+	while (i < args_nr) {
 		char *arg_temp = dma_arg[i];
-		rte_strsplit(arg_temp, strlen(arg_temp), ptrs, 2, '@');
+		uint8_t sub_nr;
+		sub_nr = rte_strsplit(arg_temp, strlen(arg_temp), ptrs, 2,

'@');

Quoted 17 lines
examples/vhost/ioat.c +5 -1
+		if (sub_nr != 2) {
+			ret = -1;
+			goto out;
+		}
 
 		start = strstr(ptrs[0], "txd");
 		if (start == NULL) {
@@ -105,7 +110,7 @@ open_ioat(const char *value)
 
 		dma_info->nr++;
 		i++;
-	} while (i < args_nr);
+	}
 out:
 	free(input);
 	return ret;
#3 lore raw

PATCH v2 1/1 examples/vhost: fix string split error handling issue

In reply to Cheng Jiang

Add checking return value of string split function to fix the coverity issue.

Fixes 3a04ecb21420 ("examples/vhost: add async vhost args parsing")

Coverity issue: 363739

---
v2: checked args_nr explicitly

 examples/vhost/ioat.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
examples/vhost/ioat.c +13 -4
index b2c74f6537..720c0b0b81 100644
@@ -36,7 +36,7 @@ open_ioat(const char *value)
 	int ret = 0;
 	uint16_t i = 0;
 	char *dma_arg[MAX_VHOST_DEVICE];
-	uint8_t args_nr;
+	int args_nr;
 
 	while (isblank(*addrs))
 		addrs++;
@@ -54,9 +54,18 @@ open_ioat(const char *value)
 	}
 	args_nr = rte_strsplit(substr, strlen(substr),
 			dma_arg, MAX_VHOST_DEVICE, ',');
-	do {
+	if (args_nr <= 0) {
+		ret = -1;
+		goto out;
+	}
+	while (i < args_nr) {
 		char *arg_temp = dma_arg[i];
-		rte_strsplit(arg_temp, strlen(arg_temp), ptrs, 2, '@');
+		uint8_t sub_nr;
+		sub_nr = rte_strsplit(arg_temp, strlen(arg_temp), ptrs, 2, '@');
+		if (sub_nr != 2) {
+			ret = -1;
+			goto out;
+		}
 
 		start = strstr(ptrs[0], "txd");
 		if (start == NULL) {
@@ -105,7 +114,7 @@ open_ioat(const char *value)
 
 		dma_info->nr++;
 		i++;
-	} while (i < args_nr);
+	}
 out:
 	free(input);
 	return ret;

--
2.29.2

Reviewed-by on v2 1/1
#4 lore raw
Quoted 4 lines · Cheng Jiang

Add checking return value of string split function to fix the coverity issue.

Fixes 3a04ecb21420 ("examples/vhost: add async vhost args parsing")
Quoted 8 lines

Coverity issue: 363739

---
v2: checked args_nr explicitly

 examples/vhost/ioat.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

Thanks,
Maxime

#5 lore raw
In reply to Cheng Jiang
Quoted 4 lines · Cheng Jiang

Add checking return value of string split function to fix the coverity issue.

Fixes 3a04ecb21420 ("examples/vhost: add async vhost args parsing")
Quoted 8 lines

Coverity issue: 363739

---
v2: checked args_nr explicitly

 examples/vhost/ioat.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

Applied to dpdk-next-virtio/main.

Thanks,
Maxime