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

Commit

Permalink
Browse files Browse the repository at this point in the history
windows: strip '\??\' from readlink path buffer.
  • Loading branch information
Igor Zinkovsky committed Sep 14, 2011
1 parent 65c8a72 commit 2931bdc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
22 changes: 16 additions & 6 deletions src/win/fs.c
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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;

Expand Down
1 change: 0 additions & 1 deletion test/test-list.h
Expand Up @@ -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)

Expand Down

0 comments on commit 2931bdc

Please sign in to comment.