Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
windows: detect when GetCurrentDirectoryW returns more than MAX_PATH …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
piscisaureus committed Jun 5, 2012
1 parent c8c9fe1 commit a0d2af0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/win/util.c
Expand Up @@ -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) {
Expand All @@ -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. */
Expand Down

0 comments on commit a0d2af0

Please sign in to comment.