qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCHv2 2/2] envlist.c: handle strdup failure


From: Andreas Färber
Subject: Re: [Qemu-devel] [PATCHv2 2/2] envlist.c: handle strdup failure
Date: Fri, 17 Aug 2012 18:08:09 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120713 Thunderbird/14.0

Am 17.08.2012 17:34, schrieb Jim Meyering:
> Andreas Färber wrote:
> 
>> Am 17.08.2012 15:35, schrieb Jim Meyering:
>>> Jim Meyering 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 | 12 ++++++++++--
>>>>  1 file changed, 10 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/envlist.c b/envlist.c
>>>> index be0addb..7532091 100644
>>>> --- a/envlist.c
>>>> +++ b/envlist.c
>>>> @@ -234,8 +234,16 @@ envlist_to_environ(const envlist_t *envlist, size_t 
>>>> *count)
>>>>                  return (NULL);
>>>>
>>>>          for (entry = envlist->el_entries.lh_first; entry != NULL;
>>>> -            entry = entry->ev_link.le_next) {
>>>> -                *(penv++) = strdup(entry->ev_var);
>>>> +             entry = entry->ev_link.le_next, penv++) {
>>>> +                *penv = strdup(entry->ev_var);
>>>> +                if (*penv == NULL) {
>>>> +                        char **e = env;
>>>> +                        while (e <= penv) {
>>>> +                                free(*e++);
>>>> +                        }
>>>> +                        free(env);
>>>> +                        return NULL;
>>>> +                }
>>>>          }
>>>>          *penv = NULL; /* NULL terminate the list */
>>>
>>> It seems this has been lost in this list's high volume of patches.
>>> Anyone interested?  Repost desired?
>>
>> You announced a v3 but replied to v2?
> 
> Here are links to v3:
> 
>   [PATCHv3 1/2] envlist.c: convert each TAB(width-4) to equivalent spaces
>   https://lists.gnu.org/archive/html/qemu-devel/2012-05/msg02967.html
> 
>   [Qemu-devel] [PATCHv3 2/2] envlist.c: handle strdup failure
>   https://lists.gnu.org/archive/html/qemu-devel/2012-05/msg02966.html

I commented on v3. For practical reasons please ping the latest patches
and prefer Patchwork links so that no <address@hidden> gets committed by
accident.

Thanks for your efforts in reviewing and fixing all these issues!

Andreas

> 
>> Indentation looks odd in 2/2, too.
> 
> That was fixed in v3.
> 


-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg



reply via email to

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