New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows: uv_os_getenv() with empty (but defined) variable #2413
Comments
os_env_exists() fails on MSVC build: os_env_exists:104: uv_os_getenv(EMPTY_VAR) failed: -4094 UNKNOWN - Revert 396a394 - HACK: Windows: return TRUE if uv_os_getenv() returns UV_UNKNOWN, until libuv bug is fixed: libuv/libuv#2413 ref neovim@396a394#r34642361
os_env_exists() fails on MSVC build: os_env_exists:104: uv_os_getenv(EMPTY_VAR) failed: -4094 UNKNOWN - Revert 396a394 - HACK: Windows: return TRUE if uv_os_getenv() returns UV_UNKNOWN, until libuv bug is fixed: libuv/libuv#2413 ref 396a394#r34642361
So, I wrote cjihrig@3377726, which I expected to be a straightforward fix. But, there seems to be a second issue. While trying to write a test for this issue, I set an environment variable to the empty string. Windows seems to delete the environment variable instead. There's a good chance I'm doing something wrong, and I don't have a Windows setup to test on, but that's where I'm at currently. EDIT: It looks like Ruby avoids |
@cjihrig What Ruby does looks sensible IMHO. I do have a Windows laptop up and running if you want me to test stuff. |
@cjihrig cjihrig@3377726 and the following patch seems to have fixed the neovim issue. I think Ref. https://docs.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-getlasterror diff --git a/src/win/util.c b/src/win/util.c
index 54cf4f42..2fef4c5c 100644
--- a/src/win/util.c
+++ b/src/win/util.c
@@ -1412,13 +1412,13 @@ int uv_os_getenv(const char* name, char* buffer, size_t* size) {
if (r != 0)
return r;
+ SetLastError(ERROR_SUCCESS);
len = GetEnvironmentVariableW(name_w, var, MAX_ENV_VAR_LENGTH);
+ r = GetLastError();
uv__free(name_w);
assert(len < MAX_ENV_VAR_LENGTH); /* len does not include the null */
if (len == 0) {
- r = GetLastError();
-
if (r == ERROR_ENVVAR_NOT_FOUND)
return UV_ENOENT;
I don't know how you set the environment variable to empty string, but the following code appears to create an empty environment variable. SetEnvironmentVariableW(L"FOO", L"");
uv_os_setenv("BAR", ""); |
Fixes: libuv#2413 PR-URL: libuv#2419 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
uv__convert_utf8_to_utf16() always null terminates its UTF-16 output. This commit updates the code to use L'\0' as the terminator, instead of '\0'. Fixes: libuv#2413 PR-URL: libuv#2419 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit adds Windows support for retrieving empty environment variables via uv_os_getenv(). Fixes: libuv#2413 PR-URL: libuv#2419 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit adds Windows support for retrieving empty environment variables via uv_os_getenv(). Fixes: libuv#2413 PR-URL: libuv#2419 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
uv__convert_utf8_to_utf16() always null terminates its UTF-16 output. This commit updates the code to use L'\0' as the terminator, instead of '\0'. Fixes: libuv#2413 PR-URL: libuv#2419 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Fixes: libuv#2413 PR-URL: libuv#2419 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit adds Windows support for retrieving empty environment variables via uv_os_getenv(). Fixes: libuv#2413 PR-URL: libuv#2419 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
uv__convert_utf8_to_utf16() always null terminates its UTF-16 output. This commit updates the code to use L'\0' as the terminator, instead of '\0'. Fixes: libuv#2413 PR-URL: libuv#2419 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Fixes: libuv#2413 PR-URL: libuv#2419 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
If an env var is defined as empty:
The libuv Windows impl of
uv_os_getenv
returns-4094
(UV_UNKNOWN
).According to this post,
But libuv checks
GetEnvironmentVariableW() == 0
, then returnsuv_translate_sys_error(0)
.libuv/src/win/util.c
Lines 1484 to 1505 in 8ed9112
It should instead return
0
withbuffer
size of0
.The text was updated successfully, but these errors were encountered: