From 2931bdcf54556736260cc886a0908cc7ac292d5b Mon Sep 17 00:00:00 2001 From: Igor Zinkovsky Date: Tue, 13 Sep 2011 17:37:26 -0700 Subject: [PATCH] windows: strip '\??\' from readlink path buffer. --- src/win/fs.c | 22 ++++++++++++++++------ test/test-list.h | 1 - 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/win/fs.c b/src/win/fs.c index d013b589..23a19ddf 100644 --- a/src/win/fs.c +++ b/src/win/fs.c @@ -605,6 +605,8 @@ void fs__readlink(uv_fs_t* req, const char* path) { DWORD bytes_returned; REPARSE_DATA_BUFFER* reparse_data; int utf8size; + wchar_t* substitute_name; + int substitute_name_length; symlink = CreateFileA(path, 0, @@ -648,8 +650,17 @@ void fs__readlink(uv_fs_t* req, const char* path) { goto done; } - utf8size = uv_utf16_to_utf8(reparse_data->SymbolicLinkReparseBuffer.PathBuffer + (reparse_data->SymbolicLinkReparseBuffer.SubstituteNameOffset / sizeof(wchar_t)), - reparse_data->SymbolicLinkReparseBuffer.SubstituteNameLength / sizeof(wchar_t), + substitute_name = reparse_data->SymbolicLinkReparseBuffer.PathBuffer + (reparse_data->SymbolicLinkReparseBuffer.SubstituteNameOffset / sizeof(wchar_t)); + substitute_name_length = reparse_data->SymbolicLinkReparseBuffer.SubstituteNameLength / sizeof(wchar_t); + + /* Strip off the leading \??\ from the substitute name buffer.*/ + if (memcmp(substitute_name, L"\\??\\", 8) == 0) { + substitute_name += 4; + substitute_name_length -= 4; + } + + utf8size = uv_utf16_to_utf8(substitute_name, + substitute_name_length, NULL, 0); if (!utf8size) { @@ -663,10 +674,8 @@ void fs__readlink(uv_fs_t* req, const char* path) { uv_fatal_error(ERROR_OUTOFMEMORY, "malloc"); } - req->flags |= UV_FS_FREE_PTR; - - utf8size = uv_utf16_to_utf8(reparse_data->SymbolicLinkReparseBuffer.PathBuffer + (reparse_data->SymbolicLinkReparseBuffer.SubstituteNameOffset / sizeof(wchar_t)), - reparse_data->SymbolicLinkReparseBuffer.SubstituteNameLength / sizeof(wchar_t), + utf8size = uv_utf16_to_utf8(substitute_name, + substitute_name_length, req->ptr, utf8size); if (!utf8size) { @@ -675,6 +684,7 @@ void fs__readlink(uv_fs_t* req, const char* path) { goto done; } + req->flags |= UV_FS_FREE_PTR; ((char*)req->ptr)[utf8size] = '\0'; result = 0; diff --git a/test/test-list.h b/test/test-list.h index d510be29..5f1100c9 100644 --- a/test/test-list.h +++ b/test/test-list.h @@ -196,7 +196,6 @@ TASK_LIST_START TEST_ENTRY (fs_utime) TEST_ENTRY (fs_futime) TEST_ENTRY (fs_symlink) - TEST_ENTRY (fs_symlink) TEST_ENTRY (threadpool_queue_work_simple)