-
Notifications
You must be signed in to change notification settings - Fork 588
Closed
Description
I found that getenv
and setenv
in libc are not thread-safe [1], and most impl of localtime_r
in libc directly call getenv
[2]. This means that localtime_r
may have data race with setenv
.
In order to ensure soundness of setenv
, libstd add a lock to it [1], but this means that using getenv
without libstd will be unsound.
This problem is not easy to reproduce on glibc, because glibc's localtime_r
caches timezone. but using musl can easily reproduce it.
- libstd: Add thread unsafety warnings around setenv() and unsetenv() rust-lang/rust#24741
- https://github.com/aosp-mirror/platform_bionic/blob/master/libc/tzcode/localtime.c#L1321 and https://git.musl-libc.org/cgit/musl/tree/src/time/__tz.c#n127
POC: https://gist.github.com/quininer/2063c31b0bc1753989122e782b182bea
yerke, mati865, jonasbb, Milo123459, fogti and 16 morematthieu-m, Miaxos, seanpianka, Noah-Kennedy, murilobsd and 6 more
Metadata
Metadata
Assignees
Labels
No labels