diff options
author | John Högberg <[email protected]> | 2017-11-22 13:19:57 +0100 |
---|---|---|
committer | John Högberg <[email protected]> | 2018-01-03 08:14:28 +0100 |
commit | c2d70945dce9cb09d5d7120d6e9ddf7faac8d230 (patch) | |
tree | 3cfbaca9af7b6a32871e669a39027ce987c846da /erts/emulator/beam/utils.c | |
parent | be9f93b14e0fb9ff09db36abde62ae8099bf5bd0 (diff) | |
download | otp-c2d70945dce9cb09d5d7120d6e9ddf7faac8d230.tar.gz otp-c2d70945dce9cb09d5d7120d6e9ddf7faac8d230.tar.bz2 otp-c2d70945dce9cb09d5d7120d6e9ddf7faac8d230.zip |
Replace the libc environment with a thread-safe emulation
putenv(3) and friends aren't thread-safe regardless of how you slice
it; a global lock around all environment operations (like before)
keeps things safe as far as our own operations go, but we have
absolutely no control over what libc or a library dragged in by a
driver/NIF does -- they're free to call getenv(3) or putenv(3)
without honoring our lock.
This commit solves this by setting up an "emulated" environment which
can't be touched without going through our interfaces. Third-party
libraries can still shoot themselves in the foot but benign uses of
os:putenv/2 will no longer risk crashing the emulator.
Diffstat (limited to 'erts/emulator/beam/utils.c')
-rw-r--r-- | erts/emulator/beam/utils.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/erts/emulator/beam/utils.c b/erts/emulator/beam/utils.c index 993585be10..fe9f1c7606 100644 --- a/erts/emulator/beam/utils.c +++ b/erts/emulator/beam/utils.c @@ -4360,15 +4360,20 @@ erts_read_env(char *key) char *value = erts_alloc(ERTS_ALC_T_TMP, value_len); int res; while (1) { - res = erts_sys_getenv_raw(key, value, &value_len); - if (res <= 0) - break; - value = erts_realloc(ERTS_ALC_T_TMP, value, value_len); + res = erts_sys_explicit_8bit_getenv(key, value, &value_len); + + if (res >= 0) { + break; + } + + value = erts_realloc(ERTS_ALC_T_TMP, value, value_len); } - if (res != 0) { - erts_free(ERTS_ALC_T_TMP, value); - return NULL; + + if (res != 1) { + erts_free(ERTS_ALC_T_TMP, value); + return NULL; } + return value; } |