[release-0.4] env: use putenv_s for LC_ALL, LANG, etc. #11050

Problem:  ":lang messages en_US.UTF-8" no longer overrides the language
          detected from the environment (at startup).
Solution: In os_setenv, special-case "LC_ALL", "LANG", et al. to use
          putenv_s instead of uv_os_setenv.

fixes #11045
This commit is contained in:
erw7 2019-09-22 16:02:28 +09:00 committed by Daniel Hahler
parent 36e2846b49
commit 6f693be1ee

View File

@ -135,7 +135,16 @@ int os_setenv(const char *name, const char *value, int overwrite)
}
#endif
uv_mutex_lock(&mutex);
int r = uv_os_setenv(name, value);
int r;
#ifdef WIN32
// libintl uses getenv() for LC_ALL/LANG/etc., so we must use _putenv_s().
if (striequal(name, "LC_ALL") || striequal(name, "LANGUAGE")
|| striequal(name, "LANG") || striequal(name, "LC_MESSAGES")) {
r = _putenv_s(name, value); // NOLINT
assert(r == 0);
}
#endif
r = uv_os_setenv(name, value);
assert(r != UV_EINVAL);
// Destroy the old map item. Do this AFTER uv_os_setenv(), because `value`
// could be a previous os_getenv() result.