windows: detect when GetCurrentDirectoryW returns more than MAX_PATH chars
This should never happen. However the CRT has a code path to deal with this situation, so at least detect it when it happens and return an error, instead of potentially opening a security hole.
This commit is contained in:
parent
c8c9fe1c74
commit
a0d2af0fd2
@ -154,7 +154,7 @@ int uv_exepath(char* buffer, size_t* size_ptr) {
|
||||
|
||||
uv_err_t uv_cwd(char* buffer, size_t size) {
|
||||
DWORD utf16_len;
|
||||
WCHAR utf16_buffer[MAX_PATH + 1];
|
||||
WCHAR utf16_buffer[MAX_PATH];
|
||||
int r;
|
||||
|
||||
if (buffer == NULL || size == 0) {
|
||||
@ -164,6 +164,10 @@ uv_err_t uv_cwd(char* buffer, size_t size) {
|
||||
utf16_len = GetCurrentDirectoryW(MAX_PATH, utf16_buffer);
|
||||
if (utf16_len == 0) {
|
||||
return uv__new_sys_error(GetLastError());
|
||||
} else if (utf16_len > MAX_PATH) {
|
||||
/* This should be impossible; however the CRT has a code path to deal */
|
||||
/* with this scenario, so I added a check anyway. */
|
||||
return uv__new_artificial_error(UV_EIO);
|
||||
}
|
||||
|
||||
/* utf16_len contains the length, *not* including the terminating null. */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user