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
Metadata
Metadata
Assignees
Labels
No labels