examples/vhost: fix string split error handling
authorCheng Jiang <cheng1.jiang@intel.com>
Wed, 11 Nov 2020 09:08:06 +0000 (09:08 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 13 Nov 2020 18:43:26 +0000 (19:43 +0100)
Add checking return value of string split function to fix the
coverity issue.

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

Signed-off-by: Cheng Jiang <cheng1.jiang@intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
examples/vhost/ioat.c

index b2c74f6..720c0b0 100644 (file)
@@ -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;