From d03abfd4007f5b073c406a0d3afe37e6d8407f49 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 1 Dec 2015 17:41:38 +0100 Subject: [PATCH] win: work around sharepoint scandir bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It has been reported that for SharePoint connections mapped as a drive, uv_fs_scandir() returns "." and ".." entries when the expectation is that they should be filtered out. After some investigation it looks like the driver returns ".\0" and "..\0" for those entries, that is, it includes the zero byte in the filename length. Rewrite the filter to catch those entries as well. Fixes: https://github.com/nodejs/node/issues/4002 PR-URL: https://github.com/libuv/libuv/pull/636 Reviewed-By: Alexis Campailla Reviewed-By: Colin Ihrig Reviewed-By: Saúl Ibarra Corretgé --- src/win/fs.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/win/fs.c b/src/win/fs.c index 16e3ae7cf1b..fd2547e941b 100644 --- a/src/win/fs.c +++ b/src/win/fs.c @@ -901,7 +901,15 @@ void fs__scandir(uv_fs_t* req) { /* Compute the length of the filename in WCHARs. */ wchar_len = info->FileNameLength / sizeof info->FileName[0]; - /* Skip over '.' and '..' entries. */ + /* Skip over '.' and '..' entries. It has been reported that + * the SharePoint driver includes the terminating zero byte in + * the filename length. Strip those first. + */ + while (wchar_len > 0 && info->FileName[wchar_len - 1] == L'\0') + wchar_len -= 1; + + if (wchar_len == 0) + continue; if (wchar_len == 1 && info->FileName[0] == L'.') continue; if (wchar_len == 2 && info->FileName[0] == L'.' &&