Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14390

Re: [PATCH] Fix null environ crash in getenv() provided by lib/sh/getenv.c

Path csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail
From Eric Blake <eblake@redhat.com>
Newsgroups gnu.bash.bug
Subject Re: [PATCH] Fix null environ crash in getenv() provided by lib/sh/getenv.c
Date Tue, 24 Jul 2018 09:14:56 -0500
Organization Red Hat, Inc.
Lines 31
Approved bug-bash@gnu.org
Message-ID <mailman.4136.1532441704.1292.bug-bash@gnu.org> (permalink)
References <CAKxOVBsO-n8-M1Ynq9cz9xgu6b7kHvYX8Tnz324cstJbjbjEDQ@mail.gmail.com> <912d7688-abf8-d253-1da1-f79c6f9627b7@case.edu>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace usenet.stanford.edu 1532441705 18798 208.118.235.17 (24 Jul 2018 14:15:05 GMT)
X-Complaints-To action@cs.stanford.edu
To chet.ramey@case.edu, Keeley Hoek <keeley@hoek.io>, bug-bash@gnu.org
Envelope-to bug-bash@gnu.org
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0
In-Reply-To <912d7688-abf8-d253-1da1-f79c6f9627b7@case.edu>
Content-Language en-US
X-Scanned-By MIMEDefang 2.78 on 10.11.54.4
X-Greylist Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 24 Jul 2018 14:14:57 +0000 (UTC)
X-Greylist inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 24 Jul 2018 14:14:57 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:''
X-detected-operating-system by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy]
X-Received-From 66.187.233.73
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.21
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <http://lists.gnu.org/archive/html/bug-bash/>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
Xref csiph.com gnu.bash.bug:14390

Show key headers only | View raw


On 07/09/2018 09:16 AM, Chet Ramey wrote:
> On 7/8/18 7:21 AM, Keeley Hoek wrote:
>> In running bash on an embedded target, bash crashes for the silly
>> reason that environ is NULL.
>>
>> I haven't been able to tell whether this is actually permitted by the
>> standard (as if?), but in bash I think this behavior is inconsistent
>> anyway because:
> 
> It's probably permitted by the standard simply because the standard doesn't
> specify the value of environ. As a practical matter, on Unix systems, even
> when execve() is supplied a NULL third argument, environ is never null.
> It's not unreasonable to check for it, though.

It's unspecified by the standard, so portable programs should not assume 
it works.  The only portable thing for emptying the environment is to 
assign environ to a 1-element array containing a NULL pointer - but even 
that is not portable as a completely empty environment wipes out PATH 
and possibly other important variables (such as POSIXLY_CORRECT) that 
may subtly break expectations.

That said, Cygwin was just recently patched to allow environ=NULL as 
shorthand for emptying the environment:
https://cygwin.com/ml/cygwin-patches/2018-q2/msg00045.html
https://cygwin.com/ml/cygwin/2018-05/msg00334.html

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: [PATCH] Fix null environ crash in getenv() provided by lib/sh/getenv.c Eric Blake <eblake@redhat.com> - 2018-07-24 09:14 -0500

csiph-web