[v1] app/testpmd: fix dereference before null check

Message ID 20211209162727.12295-1-sean.morrissey@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series [v1] app/testpmd: fix dereference before null check |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS

Commit Message

Sean Morrissey Dec. 9, 2021, 4:27 p.m. UTC
  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")
Cc: stable@dpdk.org
Cc: wei.zhao1@intel.com

Signed-off-by: Sean Morrissey <sean.morrissey@intel.com>
---
 app/test-pmd/cmdline_flow.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Ferruh Yigit Jan. 18, 2022, 9:59 a.m. UTC | #1
On 12/9/2021 4:27 PM, Sean Morrissey wrote:
> 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")
> Cc: stable@dpdk.org
> Cc: wei.zhao1@intel.com
> 
> Signed-off-by: Sean Morrissey <sean.morrissey@intel.com>
> ---
>   app/test-pmd/cmdline_flow.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
> index bbe3dc0115..5bb7abcced 100644
> --- a/app/test-pmd/cmdline_flow.c
> +++ b/app/test-pmd/cmdline_flow.c
> @@ -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;
> +

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,
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>

Please keep the tag in next version.
  

Patch

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index bbe3dc0115..5bb7abcced 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -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;