Skip to contentSkip to conversation

app/testpmd: fix dereference before null check

PATCH Superseded Sean Morrissey 2 participants 4 messages Dec 9, 2021 – Jan 18, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 app/testpmd: fix dereference before null check

Assign 'left' variable only after null check on 'size' as function returns if 'size' is null.

Coverity issue: 374381

Fixes 169a9fed1f4 ("app/testpmd: fix hex string parser support for flow API")
---
 app/test-pmd/cmdline_flow.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
app/test-pmd/cmdline_flow.c +2 -1
index bbe3dc0115..5bb7abcced 100644
@@ -7702,7 +7702,6 @@ parse_string(struct context *ctx, const struct token *token,
 static int
 parse_hex_string(const char *src, uint8_t *dst, uint32_t *size)
 {
-	uint32_t left = *size;
 	const uint8_t *head = dst;
 
 	/* Check input parameters */
@@ -7712,6 +7711,8 @@ parse_hex_string(const char *src, uint8_t *dst, uint32_t *size)
 		(*size == 0))
 		return -1;
 
+	uint32_t left = *size;
+
 	/* Convert chars to bytes */
 	while (left) {
 		char tmp[3], *end = tmp;
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 26 lines · Sean Morrissey

Assign 'left' variable only after null check on 'size' as function returns if 'size' is null.

Coverity issue: 374381

Fixes 169a9fed1f4 ("app/testpmd: fix hex string parser support for flow API")
---
  app/test-pmd/cmdline_flow.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
app/test-pmd/cmdline_flow.c +0 -1
index bbe3dc0115..5bb7abcced 100644
@@ -7702,7 +7702,6 @@ parse_string(struct context *ctx, const struct token *token,
  static int
  parse_hex_string(const char *src, uint8_t *dst, uint32_t *size)
  {
-	uint32_t left = *size;
  	const uint8_t *head = dst;
 
  	/* Check input parameters */

app/test-pmd/cmdline_flow.c parse_hex_string(const char *src, uint8_t *dst, uint32_t *size) · line 7715

Quoted 5 lines
app/test-pmd/cmdline_flow.c +2 -0
@@ -7712,6 +7711,8 @@ parse_hex_string(const char *src, uint8_t *dst, uint32_t *size)
  		(*size == 0))
  		return -1;
 
+	uint32_t left = *size;
+

Hi Sean,

Change looks good but can you please move variable declaration to the beginning of the scope, like:

uint32_t left;

<null checks>

  left = *size;

With above change,

Please keep the tag in next version.

#2 lore raw

PATCH v2 1/1 app/testpmd: fix dereference before null check

In reply to Sean Morrissey

Assign 'left' variable only after null check on 'size' as function returns if 'size' is null.

Coverity issue: 374381

Fixes 169a9fed1f4 ("app/testpmd: fix hex string parser support for flow API")
---
 app/test-pmd/cmdline_flow.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
app/test-pmd/cmdline_flow.c +3 -1
index 5c2bba48ad..bbaf18d76e 100644
@@ -7702,8 +7702,8 @@ parse_string(struct context *ctx, const struct token *token,
 static int
 parse_hex_string(const char *src, uint8_t *dst, uint32_t *size)
 {
-	uint32_t left = *size;
 	const uint8_t *head = dst;
+	uint32_t left;
 
 	/* Check input parameters */
 	if ((src == NULL) ||
@@ -7712,6 +7712,8 @@ parse_hex_string(const char *src, uint8_t *dst, uint32_t *size)
 		(*size == 0))
 		return -1;
 
+	left = *size;
+
 	/* Convert chars to bytes */
 	while (left) {
 		char tmp[3], *end = tmp;
Signature · 1 line
2.25.1