Skip to contentSkip to conversation

app/testpmd: fix dereference null return valiue

PATCH Applied Jasvinder Singh 2 participants 2 messages Jan 22, 2018 – Jan 31, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 app/testpmd: fix dereference null return valiue

Malloc() function might return NULL due to insufficient space. Therefore, check for handling memory allocation failure is added.

Coverity issue: 257039

Fixes e63b50162aa3 ("app/testpmd: clean metering and policing commands")
---
 app/test-pmd/cmdline_mtr.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
app/test-pmd/cmdline_mtr.c +5 -1
index 96a851b..f908fb3 100644
@@ -86,6 +86,8 @@ parse_dscp_table_entries(char *str, enum rte_mtr_color *dscp_table)
 	/* Allocate memory for dscp table */
 	dscp_table = (enum rte_mtr_color *)malloc(MAX_DSCP_TABLE_ENTRIES *
 		sizeof(enum rte_mtr_color));
+	if (dscp_table == NULL)
+		return -1;
 
 	while (1) {
 		if (strcmp(token, "G") == 0 ||
@@ -105,8 +107,10 @@ parse_dscp_table_entries(char *str, enum rte_mtr_color *dscp_table)
 			break;
 
 		token = strtok_r(str, PARSE_DELIMITER, &str);
-		if (token == NULL)
+		if (token == NULL) {
+			free(dscp_table);
 			return -1;
+		}
 	}
 	return 0;
 }
Signature · 1 line
2.9.3
#1 lore raw

22/01/2018 16:15, Jasvinder Singh:

Quoted 7 lines

Malloc() function might return NULL due to insufficient space. Therefore, check for handling memory allocation failure is added.

Coverity issue: 257039

Fixes e63b50162aa3 ("app/testpmd: clean metering and policing commands")

Applied, thanks