From 02d8cd1aef6dd237588b159671c96112776144c9 Mon Sep 17 00:00:00 2001 From: "Min Hu (Connor)" Date: Thu, 6 May 2021 14:13:59 +0800 Subject: [PATCH] app/crypto-perf: check memory allocation [ upstream commit 37c0359bc550e0cf3938382553c7dbb4fb21567d ] 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") Signed-off-by: Min Hu (Connor) Acked-by: Akhil Goyal --- app/test-crypto-perf/cperf_options_parsing.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-crypto-perf/cperf_options_parsing.c index 22bf9cd4d6..e16e8eca9c 100644 --- a/app/test-crypto-perf/cperf_options_parsing.c +++ b/app/test-crypto-perf/cperf_options_parsing.c @@ -495,6 +495,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;