[v2,11/16] app/test: verify strdup return value

Message ID 20231110100117.8350-12-fengchengwen@huawei.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series verify strdup return value |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

fengchengwen Nov. 10, 2023, 10:01 a.m. UTC
  Add verify strdup return value logic.

Fixes: af75078fece3 ("first public release")
Cc: stable@dpdk.org

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
 app/test/process.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

lihuisong (C) Nov. 21, 2023, 3:33 a.m. UTC | #1
Acked-by: Huisong Li <lihuisong@huawei.com>

在 2023/11/10 18:01, Chengwen Feng 写道:
> Add verify strdup return value logic.
>
> Fixes: af75078fece3 ("first public release")
> Cc: stable@dpdk.org
>
> Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
> ---
>   app/test/process.h | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/app/test/process.h b/app/test/process.h
> index af7bc3e0de..c576c42349 100644
> --- a/app/test/process.h
> +++ b/app/test/process.h
> @@ -59,8 +59,11 @@ process_dup(const char *const argv[], int numargs, const char *env_value)
>   		return -1;
>   	else if (pid == 0) {
>   		/* make a copy of the arguments to be passed to exec */
> -		for (i = 0; i < numargs; i++)
> +		for (i = 0; i < numargs; i++) {
>   			argv_cpy[i] = strdup(argv[i]);
> +			if (argv_cpy[i] == NULL)
> +				rte_panic("Error dup args\n");
> +		}
>   		argv_cpy[i] = NULL;
>   		num = numargs;
>
  

Patch

diff --git a/app/test/process.h b/app/test/process.h
index af7bc3e0de..c576c42349 100644
--- a/app/test/process.h
+++ b/app/test/process.h
@@ -59,8 +59,11 @@  process_dup(const char *const argv[], int numargs, const char *env_value)
 		return -1;
 	else if (pid == 0) {
 		/* make a copy of the arguments to be passed to exec */
-		for (i = 0; i < numargs; i++)
+		for (i = 0; i < numargs; i++) {
 			argv_cpy[i] = strdup(argv[i]);
+			if (argv_cpy[i] == NULL)
+				rte_panic("Error dup args\n");
+		}
 		argv_cpy[i] = NULL;
 		num = numargs;