diff options
author | Bartosz Sosnowski <bartosz@janeasystems.com> | 2020-07-22 13:55:11 +0300 |
---|---|---|
committer | Bartosz Sosnowski <bartosz@janeasystems.com> | 2020-08-20 13:36:32 +0300 |
commit | de565ad1b2de6d173a9ea5e1932e3d85472d4c23 (patch) | |
tree | 734cfcfbbc6f83280774b410311b7303f7e758b7 /src | |
parent | 03293aa3a1e810c5ae6938cae41bf62ae418bb5f (diff) |
process: correctly parse Unicode in NODE_OPTIONS
Fixes an issue on Windows, where Unicode in NODE_OPTIONS was not parsed
correctly.
Fixes: https://github.com/nodejs/node/issues/34399
PR-URL: https://github.com/nodejs/node/pull/34476
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/node_credentials.cc | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/node_credentials.cc b/src/node_credentials.cc index acc48cac3c9..fa3dfa48a3c 100644 --- a/src/node_credentials.cc +++ b/src/node_credentials.cc @@ -57,8 +57,20 @@ bool SafeGetenv(const char* key, std::string* text, Environment* env) { { Mutex::ScopedLock lock(per_process::env_var_mutex); - if (const char* value = getenv(key)) { - *text = value; + + size_t init_sz = 256; + MaybeStackBuffer<char, 256> val; + int ret = uv_os_getenv(key, *val, &init_sz); + + if (ret == UV_ENOBUFS) { + // Buffer is not large enough, reallocate to the updated init_sz + // and fetch env value again. + val.AllocateSufficientStorage(init_sz); + ret = uv_os_getenv(key, *val, &init_sz); + } + + if (ret >= 0) { // Env key value fetch success. + *text = *val; return true; } } |