Making getenv more multi-threading--robust?

Florian Weimer fweimer@redhat.com
Fri Sep 14 10:09:00 GMT 2012


On 09/13/2012 12:56 PM, Stephan Bergmann wrote:
> [I had initially erroneously sent this to libc-help instead.]
>
> I stumbled over this when running the LibreOffice test suite and getting
> sporadic crashes in getenv(3).  It turns out that LibreOffice contains
> many places that call getenv (mostly to check whether to enable one
> tweak or another) at arbitrary times and from arbitrary threads, and
> apparently also contains the odd call to setenv etc. to modify the
> environment.

FWIW, the C11 standard appears to contain a getenv_s call (I haven't got 
a copy), but this seems to deal with a different issue: Apparently, 
there are implementations out there which free memory on putenv/setenv, 
invalidating pointers previously returned by getenv.

But this is suggests to me that everyone else manages getenv/environ
slightly differently from us, so we can't except much guidance from the 
standards. 8-(

-- 
Florian Weimer / Red Hat Product Security Team



More information about the Libc-alpha mailing list