app/crypto-perf: check memory allocation
authorMin Hu (Connor) <humin29@huawei.com>
Thu, 6 May 2021 06:13:59 +0000 (14:13 +0800)
committerAkhil Goyal <gakhil@marvell.com>
Wed, 12 May 2021 16:14:19 +0000 (18:14 +0200)
Return value of a function 'rte_zmalloc' is dereferenced without
checking, and it may call segmentation fault.

This patch fixed it.

Fixes: f8be1786b1b8 ("app/crypto-perf: introduce performance test application")
Cc: stable@dpdk.org
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
Acked-by: Akhil Goyal <gakhil@marvell.com>
app/test-crypto-perf/cperf_options_parsing.c

index 40b6dfb..e84f56c 100644 (file)
@@ -506,6 +506,12 @@ parse_test_name(struct cperf_options *opts,
 {
        char *test_name = (char *) rte_zmalloc(NULL,
                sizeof(char) * (strlen(arg) + 3), 0);
+       if (test_name == NULL) {
+               RTE_LOG(ERR, USER1, "Failed to rte zmalloc with size: %zu\n",
+                       strlen(arg) + 3);
+               return -1;
+       }
+
        snprintf(test_name, strlen(arg) + 3, "[%s]", arg);
        opts->test_name = test_name;