diff mbox series

[v2] examples/vhost: fix string split error handling issue

Message ID 20201111090806.43478-1-Cheng1.jiang@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers show
Series [v2] examples/vhost: fix string split error handling issue | expand

Checks

Context Check Description
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/travis-robot success Travis build: passed
ci/iol-broadcom-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Cheng Jiang Nov. 11, 2020, 9:08 a.m. UTC
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

Signed-off-by: Cheng Jiang <Cheng1.jiang@intel.com>
---
v2: checked args_nr explicitly

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

--
2.29.2

Comments

Maxime Coquelin Nov. 12, 2020, 4:53 p.m. UTC | #1
On 11/11/20 10:08 AM, Cheng Jiang wrote:
> 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
> 
> Signed-off-by: Cheng Jiang <Cheng1.jiang@intel.com>
> ---
> v2: checked args_nr explicitly
> 
>  examples/vhost/ioat.c | 17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
Maxime Coquelin Nov. 13, 2020, 8:40 a.m. UTC | #2
On 11/11/20 10:08 AM, Cheng Jiang wrote:
> 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
> 
> Signed-off-by: Cheng Jiang <Cheng1.jiang@intel.com>
> ---
> 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
diff mbox series

Patch

diff --git a/examples/vhost/ioat.c b/examples/vhost/ioat.c
index b2c74f6537..720c0b0b81 100644
--- a/examples/vhost/ioat.c
+++ b/examples/vhost/ioat.c
@@ -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;