All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jim Meyering <jim@meyering.net>
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCHv2 2/2] envlist.c: handle strdup failure
Date: Fri, 17 Aug 2012 15:35:14 +0200	[thread overview]
Message-ID: <87d32p63ql.fsf@rho.meyering.net> (raw)
In-Reply-To: <1337680210-20569-3-git-send-email-jim@meyering.net> (Jim Meyering's message of "Tue, 22 May 2012 11:50:10 +0200")

Jim Meyering wrote:
> 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 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?

 b/envlist.c |  256 ++++++++++++++++++++++++++++++------------------------------
 envlist.c   |   12 ++
 2 files changed, 138 insertions(+), 130 deletions(-)

  reply	other threads:[~2012-08-17 13:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-22  9:50 [Qemu-devel] [PATCHv2 0/2] envlist.c: handle strdup failure Jim Meyering
2012-05-22  9:50 ` [Qemu-devel] [PATCHv2 1/2] envlist.c: convert all TABs to equivalent spaces Jim Meyering
2012-05-22  9:55   ` Peter Maydell
2012-05-22 10:17     ` Jim Meyering
2012-05-22  9:50 ` [Qemu-devel] [PATCHv2 2/2] envlist.c: handle strdup failure Jim Meyering
2012-08-17 13:35   ` Jim Meyering [this message]
2012-08-17 15:10     ` Andreas Färber
2012-08-17 15:34       ` Jim Meyering
2012-08-17 16:08         ` Andreas Färber

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=87d32p63ql.fsf@rho.meyering.net \
    --to=jim@meyering.net \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.