From a5d374377822ddaa1961bddcef4bd53189c83d88 Mon Sep 17 00:00:00 2001 From: Mustafa M Date: Wed, 19 Jun 2019 12:24:36 -0400 Subject: [PATCH] win: fix uv_os_tmpdir when env var is 260 chars When TMP environment variable is 261 chars (including the trailing slash) or 260 chars without the trailing slash, uv_os_tmpdir throws an UV_EIO error which it shouldn't, since the total input string size allowable for this function is PATH_MAX+1 (including the trailing slash) PR-URL: https://github.com/libuv/libuv/pull/2341 Reviewed-By: Ben Noordhuis Reviewed-By: Bartosz Sosnowski --- src/win/util.c | 6 +++--- test/test-tmpdir.c | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/win/util.c b/src/win/util.c index 7ca83213..a8f45233 100644 --- a/src/win/util.c +++ b/src/win/util.c @@ -1171,18 +1171,18 @@ int uv_os_homedir(char* buffer, size_t* size) { int uv_os_tmpdir(char* buffer, size_t* size) { - wchar_t path[MAX_PATH + 1]; + wchar_t path[MAX_PATH + 2]; DWORD bufsize; size_t len; if (buffer == NULL || size == NULL || *size == 0) return UV_EINVAL; - len = GetTempPathW(MAX_PATH + 1, path); + len = GetTempPathW(ARRAY_SIZE(path), path); if (len == 0) { return uv_translate_sys_error(GetLastError()); - } else if (len > MAX_PATH + 1) { + } else if (len > ARRAY_SIZE(path)) { /* This should not be possible */ return UV_EIO; } diff --git a/test/test-tmpdir.c b/test/test-tmpdir.c index 29e8055f..dac488d0 100644 --- a/test/test-tmpdir.c +++ b/test/test-tmpdir.c @@ -67,5 +67,16 @@ TEST_IMPL(tmpdir) { r = uv_os_tmpdir(tmpdir, &len); ASSERT(r == UV_EINVAL); +#ifdef _WIN32 + const char *name = "TMP"; + char tmpdir_win[] = "C:\\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; + r = uv_os_setenv(name, tmpdir_win); + ASSERT(r == 0); + char tmpdirx[PATHMAX]; + size_t lenx = sizeof tmpdirx; + r = uv_os_tmpdir(tmpdirx, &lenx); + ASSERT(r == 0); +#endif + return 0; }