From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/7472 Path: news.gmane.org!not-for-mail From: Laurent Bercot Newsgroups: gmane.linux.lib.musl.general Subject: Re: setenv if value=NULL, what say standard? Bug? Date: Thu, 23 Apr 2015 02:35:15 +0200 Message-ID: <55383E43.8010505@skarnet.org> References: <553837F1.5080808@safe.ca> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1429749327 8122 80.91.229.3 (23 Apr 2015 00:35:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 23 Apr 2015 00:35:27 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-7485-gllmg-musl=m.gmane.org@lists.openwall.com Thu Apr 23 02:35:26 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Yl56y-0002vc-W0 for gllmg-musl@m.gmane.org; Thu, 23 Apr 2015 02:35:25 +0200 Original-Received: (qmail 26158 invoked by uid 550); 23 Apr 2015 00:35:23 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 26120 invoked from network); 23 Apr 2015 00:35:22 -0000 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 In-Reply-To: <553837F1.5080808@safe.ca> Xref: news.gmane.org gmane.linux.lib.musl.general:7472 Archived-At: On 23/04/2015 02:08, Jean-Marc Pigeon wrote: > My guess, glibc code is 'blindly" setting the NULL (as "") > value to the variable. > > Is the standard saying otherwise, or do we have a > a real bug in setenv?? The standard at http://pubs.opengroup.org/onlinepubs/9699919799/functions/setenv.html says... ... exactly nothing about the possibility of envval being NULL. This is, in the strictest sense, UB. :) Actually, it says "The environment variable shall be set to the value to which envval points." So, arguably, envval should point to something, and since NULL does not, it is forbidden. Another valid interpretation could be that envvar is set to the value to which envval points, i.e. no value at all, so it is unset; but it doesn't fit the spirit of setenv() to unset variables. The glibc interpretation, if it does what you think it does, is wrong in any case: the empty string is a very different thing from no value at all. I think the only safe conclusion is that the application is incorrect and should ensure that setenv() is never called with a NULL value. -- Laurent