Skip to contentSkip to conversation

app/testpmd: fix NULL pointer deref for traffic management CLI

PATCH Applied Jasvinder Singh 2 participants 3 messages Oct 27, 2017 – Nov 7, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 app/testpmd: fix NULL pointer deref for traffic management CLI

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")
---
 app/test-pmd/cmdline_tm.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
app/test-pmd/cmdline_tm.c +10 -0
index 964ce9d..b737f8a 100644
@@ -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) {
Signature · 1 line
2.9.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Jasvinder Singh

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")
Applied
#2 lore raw
Quoted 11 lines · Ferruh Yigit
Quoted 8 lines · Jasvinder Singh

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")

Applied to dpdk/master, thanks.