qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: Jim Meyering <jim@meyering.net>
Cc: Jim Meyering <meyering@redhat.com>,
	Peter Maydell <peter.maydell@linaro.org>,
	Riku Voipio <riku.voipio@iki.fi>,
	qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH for-1.2? v4 2/2] envlist.c: handle strdup failure
Date: Sun, 19 Aug 2012 15:21:00 +0200	[thread overview]
Message-ID: <5030E83C.4070800@suse.de> (raw)
In-Reply-To: <1345227891-32449-3-git-send-email-jim@meyering.net>

Am 17.08.2012 20:24, schrieb Jim Meyering:
> From: Jim Meyering <meyering@redhat.com>
> 
> 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 <meyering@redhat.com>
> ---
>  envlist.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/envlist.c b/envlist.c
> index 230596f..cf3f2d8 100644
> --- a/envlist.c
> +++ b/envlist.c
> @@ -245,8 +245,16 @@ 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);
> +         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 */
> 

Acked-by: Andreas Färber <afaerber@suse.de>

Andreas

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

      reply	other threads:[~2012-08-19 13:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-17 18:24 [Qemu-devel] [PATCHv4 0/2] envlist.c: handle strdup failure Jim Meyering
2012-08-17 18:24 ` [Qemu-devel] [PATCHv4 1/2] envlist.c: conform to QEMU's coding style Jim Meyering
2012-08-19 13:17   ` [Qemu-devel] [PATCH for-1.2? v4 " Andreas Färber
2012-08-17 18:24 ` [Qemu-devel] [PATCHv4 2/2] envlist.c: handle strdup failure Jim Meyering
2012-08-19 13:21   ` Andreas Färber [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5030E83C.4070800@suse.de \
    --to=afaerber@suse.de \
    --cc=jim@meyering.net \
    --cc=meyering@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=riku.voipio@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).