From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:58158) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T2Mho-0005rT-QJ for qemu-devel@nongnu.org; Fri, 17 Aug 2012 09:35:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T2Mhn-0003yj-ON for qemu-devel@nongnu.org; Fri, 17 Aug 2012 09:35:16 -0400 Received: from mx.meyering.net ([88.168.87.75]:44366) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T2Mhn-0003yb-HG for qemu-devel@nongnu.org; Fri, 17 Aug 2012 09:35:15 -0400 Received: from rho.meyering.net (rho.meyering.net [127.0.0.1]) by rho.meyering.net (Acme Bit-Twister) with ESMTP id B8F4B60117 for ; Fri, 17 Aug 2012 15:35:14 +0200 (CEST) From: Jim Meyering 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") References: <1337680210-20569-1-git-send-email-jim@meyering.net> <1337680210-20569-3-git-send-email-jim@meyering.net> Date: Fri, 17 Aug 2012 15:35:14 +0200 Message-ID: <87d32p63ql.fsf@rho.meyering.net> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCHv2 2/2] envlist.c: handle strdup failure List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Jim Meyering wrote: > From: Jim Meyering > > 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 > --- > 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(-)