mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: setenv if value=NULL, what say standard? Bug?
Date: Wed, 22 Apr 2015 22:15:07 -0400	[thread overview]
Message-ID: <20150423021507.GG6817@brightrain.aerifal.cx> (raw)
In-Reply-To: <55384A61.5020001@safe.ca>

On Wed, Apr 22, 2015 at 09:26:57PM -0400, Jean-Marc Pigeon wrote:
> > I think the only safe conclusion is that the application is
> > incorrect and should ensure that setenv() is never called with a
> > NULL value.
> > 
> Checked glibc, My understanding, it set something as
> "name="
> in the environment, so the variable is present but
> value is "empty"i (top application to decide what to do).
> uclibc does something similar (as far I can tell looking
> at source code)..
> 
> 
> The application is not careful enough, but not incorrect as such.

It's definitely incorrect. It's doing something that invokes undefined
behavior.

> Note: we may have tons of applications with the same problem.
> if we keep musl setenv like that, musl will be seen as quite unreliable.

No, actually glibc is fixing this bug (maybe they already did). See
the thread beginning here:

https://sourceware.org/ml/libc-alpha/2015-03/threads.html#00449

My understanding is that glibc is planning to do, or already does in
the latest version, exactly what musl is doing.

> If this situation is indeed UB, there is 2 options for musl:
> 1) Swallow the problem nicely... as glibc and uclibc does.
> 2) Report an error.. EINVAL? (and document it in manual)
> 
> Crashing at "libc" level is not an option.

I can see how it might seem like that at first, but crashing is
actually the best possible behavior. Options 1 and 2 cover up a
potentially serious bug -- it's not clear what the application was
trying to do, most likely nobody even thought about what they were
trying to do, and even if they did have something in mind it's not
reliable or portable. The glibc wiki has some text taken from text I
wrote on the topic (copied from a stack overflow answer I gave) here:

https://sourceware.org/glibc/wiki/Style_and_Conventions#Invalid_pointers

Specifically it covers why returning an error is not a good idea.

Rich


  reply	other threads:[~2015-04-23  2:15 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-23  0:08 Jean-Marc Pigeon
2015-04-23  0:35 ` Laurent Bercot
2015-04-23  1:26   ` Jean-Marc Pigeon
2015-04-23  2:15     ` Rich Felker [this message]
2015-04-23  4:24       ` Jean-Marc Pigeon
2015-04-23  5:08         ` Raphael Cohn
2015-04-23 12:29           ` Jean-Marc Pigeon
2015-04-23  9:23         ` Laurent Bercot
2015-04-23  9:52           ` Raphael Cohn
2015-04-23 10:47             ` Laurent Bercot
2015-04-23 10:10         ` Rich Felker
2015-04-23 12:58           ` Jean-Marc Pigeon
2015-04-23 13:22             ` Szabolcs Nagy
2015-04-23 13:58               ` Jean-Marc Pigeon
2015-04-23 14:26                 ` Szabolcs Nagy
2015-04-23  8:05       ` Jens Gustedt
2015-04-23  9:55         ` Rich Felker
2015-04-24  4:11       ` Isaac Dunham
2015-04-23  5:52   ` Isaac Dunham

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=20150423021507.GG6817@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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).