From: Jasvinder Singh Date: Fri, 27 Oct 2017 09:10:18 +0000 (+0100) Subject: app/testpmd: fix null pointer dereference X-Git-Tag: spdx-start~941 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=4f5dd001f77d01205566ed7e6349f60cd381621c;p=dpdk.git app/testpmd: fix null pointer dereference malloc() function might returns NULL when memory allocation fails due to insufficient space. Therefore, check for handling memory allocation failure is added. Coverity issue: 198442,198444 Fixes: 996cb153af06 ("app/testpmd: add commands for TM nodes and hierarchy commit") Signed-off-by: Jasvinder Singh Reviewed-by: Ferruh Yigit --- diff --git a/app/test-pmd/cmdline_tm.c b/app/test-pmd/cmdline_tm.c index 964ce9d920..b737f8a63e 100644 --- a/app/test-pmd/cmdline_tm.c +++ b/app/test-pmd/cmdline_tm.c @@ -1615,6 +1615,11 @@ static void cmd_add_port_tm_nonleaf_node_parsed(void *parsed_result, shared_shaper_id = (uint32_t *)malloc(MAX_NUM_SHARED_SHAPERS * sizeof(uint32_t)); + if (shared_shaper_id == NULL) { + printf(" Memory not allocated for shared shapers (error)\n"); + return; + } + /* Parse multi shared shaper id string */ ret = parse_multi_ss_id_str(s_str, &n_shared_shapers, shared_shaper_id); if (ret) { @@ -1770,6 +1775,11 @@ static void cmd_add_port_tm_leaf_node_parsed(void *parsed_result, shared_shaper_id = (uint32_t *)malloc(MAX_NUM_SHARED_SHAPERS * sizeof(uint32_t)); + if (shared_shaper_id == NULL) { + printf(" Memory not allocated for shared shapers (error)\n"); + return; + } + /* Parse multi shared shaper id string */ ret = parse_multi_ss_id_str(s_str, &n_shared_shapers, shared_shaper_id); if (ret) {