[dpdk-dev] app/crypto-perf: fix dereference null return value

Message ID 1486392910-8183-1-git-send-email-slawomirx.mrozowicz@intel.com (mailing list archive)
State Changes Requested, archived
Delegated to: Pablo de Lara Guarch
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel compilation fail Compilation issues

Commit Message

Slawomir Mrozowicz Feb. 6, 2017, 2:55 p.m. UTC
  Dereferencing a pointer that might be null key_token when calling strstr.
Check if the pointer is null before.

Coverity issue: 141071
Fixes: f8be1786b1b8 ("app/crypto-perf: introduce performance test application")

Signed-off-by: Slawomir Mrozowicz <slawomirx.mrozowicz@intel.com>
---
 app/test-crypto-perf/cperf_test_vector_parsing.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

De Lara Guarch, Pablo Feb. 9, 2017, 10:31 p.m. UTC | #1
Hi Slawomir,

> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Slawomir
> Mrozowicz
> Sent: Monday, February 06, 2017 2:55 PM
> To: Doherty, Declan
> Cc: dev@dpdk.org; Mrozowicz, SlawomirX
> Subject: [dpdk-dev] [PATCH] app/crypto-perf: fix dereference null return
> value
> 
> Dereferencing a pointer that might be null key_token when calling strstr.
> Check if the pointer is null before.
> 
> Coverity issue: 141071
> Fixes: f8be1786b1b8 ("app/crypto-perf: introduce performance test
> application")
> 
> Signed-off-by: Slawomir Mrozowicz <slawomirx.mrozowicz@intel.com>
> ---
>  app/test-crypto-perf/cperf_test_vector_parsing.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/app/test-crypto-perf/cperf_test_vector_parsing.c b/app/test-
> crypto-perf/cperf_test_vector_parsing.c
> index e0bcb20..a7d7b51 100644
> --- a/app/test-crypto-perf/cperf_test_vector_parsing.c
> +++ b/app/test-crypto-perf/cperf_test_vector_parsing.c
> @@ -240,7 +240,7 @@ parse_entry(char *entry, struct cperf_test_vector
> *vector,
> 
>  	/* get values for key */
>  	token = strtok(NULL, CPERF_ENTRY_DELIMITER);
> -	if (token == NULL) {
> +	if (key_token == NULL || token == NULL) {

Is this fix right? If key_token is NULL, then I would expect a seg fault here.

>  		printf("Expected 'key = values' but was '%.40s'..\n",
>  			key_token);
>  		return -1;
> --
> 2.5.0

Thanks,
Pablo
  

Patch

diff --git a/app/test-crypto-perf/cperf_test_vector_parsing.c b/app/test-crypto-perf/cperf_test_vector_parsing.c
index e0bcb20..a7d7b51 100644
--- a/app/test-crypto-perf/cperf_test_vector_parsing.c
+++ b/app/test-crypto-perf/cperf_test_vector_parsing.c
@@ -240,7 +240,7 @@  parse_entry(char *entry, struct cperf_test_vector *vector,
 
 	/* get values for key */
 	token = strtok(NULL, CPERF_ENTRY_DELIMITER);
-	if (token == NULL) {
+	if (key_token == NULL || token == NULL) {
 		printf("Expected 'key = values' but was '%.40s'..\n",
 			key_token);
 		return -1;