From 79e80a8e06ddf286b231dc853347059f6da37d39 Mon Sep 17 00:00:00 2001 From: Ilya Date: Tue, 17 Sep 2019 10:48:07 +0500 Subject: [PATCH] Refactor reparse tag checks (#10431) Reparse tag consts is absolute numbers, not flags so we should use a comparison instead of bit operations --- .../namespaces/FileSystemProvider.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index 42da77ba19c..f731a322731 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -1845,7 +1845,7 @@ private void Dir( // a) the user has asked to with the -FollowSymLinks switch parameter and // b) the directory pointed to by the symlink has not already been visited, // preventing symlink loops. - // c) it is not a reparse point with a target + // c) it is not a reparse point with a target (not OneDrive or an AppX link). if (tracker == null) { if (InternalSymbolicLinkLinkCodeMethods.IsReparsePointWithTarget(recursiveDirectory)) @@ -8069,13 +8069,15 @@ internal static bool IsReparsePointWithTarget(FileSystemInfo fileInfo) return false; } #if !UNIX + // It is a reparse point and we should check some reparse point tags. var data = new WIN32_FIND_DATA(); using (var handle = FindFirstFileEx(fileInfo.FullName, FINDEX_INFO_LEVELS.FindExInfoBasic, ref data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, 0)) { - // Name surrogates (0x20000000) are reparse points that point to other named entities local to the filesystem (like symlinks) - // In the case of OneDrive, they are not surrogates and would be safe to recurse into. - // This code is equivalent to the IsReparseTagNameSurrogate macro: https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/ntifs/nf-ntifs-isreparsetagnamesurrogate - if (!handle.IsInvalid && (data.dwReserved0 & 0x20000000) == 0 && (data.dwReserved0 & IO_REPARSE_TAG_APPEXECLINK) != IO_REPARSE_TAG_APPEXECLINK) + // The name surrogate bit 0x20000000 is defined in https://docs.microsoft.com/en-us/windows/win32/fileio/reparse-point-tags + // Name surrogates (0x20000000) are reparse points that point to other named entities local to the filesystem + // (like symlinks and mount points). + // In the case of OneDrive, they are not name surrogates and would be safe to recurse into. + if (!handle.IsInvalid && (data.dwReserved0 & 0x20000000) == 0 && (data.dwReserved0 != IO_REPARSE_TAG_APPEXECLINK)) { return false; }