From a0d2af0fd23bfc107e12aadb6ce2d6d98cb1e13f Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Tue, 5 Jun 2012 18:18:27 +0200 Subject: [PATCH] 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. --- src/win/util.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/win/util.c b/src/win/util.c index 87a999ff5..f104f00f9 100644 --- a/src/win/util.c +++ b/src/win/util.c @@ -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. */