Bug 19179 - gmtime_r internally calls getenv("TZ") which is not thread-safe
Summary: gmtime_r internally calls getenv("TZ") which is not thread-safe
Status: RESOLVED DUPLICATE of bug 14023
Alias: None
Product: glibc
Classification: Unclassified
Component: time (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-28 15:23 UTC by Szabolcs Nagy
Modified: 2015-11-02 14:45 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Szabolcs Nagy 2015-10-28 15:23:04 UTC
gmtime_r should be thread-safe, but it calls tzset_internal which calls
getenv("TZ") which is non-thread-safe.

a multi-threaded application may modify the TZ env var through the
environ pointer if there is no concurrent access to this env var in
other threads.

gmtime_r is not specified to access TZ, if it does, that can introduce
a data race in a conforming application and gmtime_r may misbehave if
it observes TZ in an inconsistent state.
Comment 1 Paul Pluzhnikov 2015-10-30 03:10:49 UTC
Dup of 14023

*** This bug has been marked as a duplicate of bug 14023 ***
Comment 2 Paul Pluzhnikov 2015-10-30 03:14:45 UTC
getenv is thread-safe (so long as other threads aren't modifying the environment), so if getenv() was the problem, this bug would be invalid.

But tzset_internal writes globals, and is definitely not thread-safe.
Comment 3 Szabolcs Nagy 2015-10-30 11:57:56 UTC
i used the wrong words there.

getenv is thread-safe, but an application is
allowed to modify an env var concurrently with
a thread-safe function except if the function
is specified to access the environment.

gmtime_r is not specified to access the env,
so it is not allowed to call getenv.

(i.e. unconditionally thread-safe functions are
not allowed to call conditionally thread-safe
ones.)