diff mbox series

[07/12] argv_parse: check return value of malloc in argv_parse()

Message ID 5d711bbc-50bb-c8a5-a118-e22a691c0d7f@huawei.com
State Superseded
Headers show
Series e2fsprogs: some bugfixs and some code cleanups | expand

Commit Message

wuguanghao May 24, 2021, 11:23 a.m. UTC
In argv_parse(), return value of malloc should be checked
whether it is NULL, otherwise, it may cause a segfault error.

Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
---
 lib/support/argv_parse.c | 2 ++
 1 file changed, 2 insertions(+)

--

Comments

wuguanghao May 25, 2021, 2:32 a.m. UTC | #1
There is a problem with this patch. "argv" is spelled as "arcv".
This problem will be resolved in the v2 version.

在 2021/5/24 19:23, Wu Guanghao 写道:
> In argv_parse(), return value of malloc should be checked
> whether it is NULL, otherwise, it may cause a segfault error.
> 
> Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
> Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
> ---
>  lib/support/argv_parse.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/lib/support/argv_parse.c b/lib/support/argv_parse.c
> index d22f6344..1ef9c014 100644
> --- a/lib/support/argv_parse.c
> +++ b/lib/support/argv_parse.c
> @@ -116,6 +116,8 @@ int argv_parse(char *in_buf, int *ret_argc, char ***ret_argv)
>  	if (argv == 0) {
>  		argv = malloc(sizeof(char *));
>  		free(buf);
> +		if (!arcv)
> +			return -1;
>  	}
>  	argv[argc] = 0;
>  	if (ret_argc)
>
diff mbox series

Patch

diff --git a/lib/support/argv_parse.c b/lib/support/argv_parse.c
index d22f6344..1ef9c014 100644
--- a/lib/support/argv_parse.c
+++ b/lib/support/argv_parse.c
@@ -116,6 +116,8 @@  int argv_parse(char *in_buf, int *ret_argc, char ***ret_argv)
 	if (argv == 0) {
 		argv = malloc(sizeof(char *));
 		free(buf);
+		if (!arcv)
+			return -1;
 	}
 	argv[argc] = 0;
 	if (ret_argc)