qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 1/3] envlist.c: handle strdup failure


From: Blue Swirl
Subject: Re: [Qemu-devel] [PATCH 1/3] envlist.c: handle strdup failure
Date: Sat, 19 May 2012 15:55:59 +0000

On Tue, May 15, 2012 at 1:04 PM,  <address@hidden> wrote:
> From: Jim Meyering <address@hidden>
>
> Without this, envlist_to_environ may silently fail to copy all
> strings into the destination buffer, and both callers would leak
> any env strings allocated after a failing strdup, because the
> freeing code stops at the first NULL pointer.
>
> Signed-off-by: Jim Meyering <address@hidden>
> ---
>  envlist.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/envlist.c b/envlist.c
> index f2303cd..2bbd99c 100644
> --- a/envlist.c
> +++ b/envlist.c
> @@ -235,7 +235,14 @@ envlist_to_environ(const envlist_t *envlist, size_t 
> *count)
>
>        for (entry = envlist->el_entries.lh_first; entry != NULL;
>            entry = entry->ev_link.le_next) {
> -               *(penv++) = strdup(entry->ev_var);
> +               if ((*(penv++) = strdup(entry->ev_var)) == NULL) {
> +                       char **e = env;
> +                       while (e != penv) {
> +                               free(*e++);
> +                       }
> +                       free(env);
> +                       return NULL;
> +               }

ERROR: code indent should never use tabs
#82: FILE: envlist.c:238:
+^I^Iif ((*(penv++) = strdup(entry->ev_var)) == NULL) {$

ERROR: do not use assignment in if condition
#82: FILE: envlist.c:238:
+               if ((*(penv++) = strdup(entry->ev_var)) == NULL) {

ERROR: code indent should never use tabs
#83: FILE: envlist.c:239:
+^I^I^Ichar **e = env;$

ERROR: code indent should never use tabs
#84: FILE: envlist.c:240:
+^I^I^Iwhile (e != penv) {$

ERROR: code indent should never use tabs
#85: FILE: envlist.c:241:
+^I^I^I^Ifree(*e++);$

ERROR: code indent should never use tabs
#86: FILE: envlist.c:242:
+^I^I^I}$

ERROR: code indent should never use tabs
#87: FILE: envlist.c:243:
+^I^I^Ifree(env);$

ERROR: code indent should never use tabs
#88: FILE: envlist.c:244:
+^I^I^Ireturn NULL;$

ERROR: code indent should never use tabs
#89: FILE: envlist.c:245:
+^I^I}$

total: 9 errors, 0 warnings, 15 lines checked

Please fix.

>        }
>        *penv = NULL; /* NULL terminate the list */
>
> --
> 1.7.10.2.484.gcd07cc5
>
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]