Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexis Christoforides <alexis@thenull.net>2019-08-09 01:11:06 +0300
committerAlexander Köplinger <alex.koeplinger@outlook.com>2019-08-09 01:11:06 +0300
commit1cf71cce533cb31d6b6efb4b1163cebaedcaacd2 (patch)
treeb50727926c48ddb6b99d0833afb687f04947ad6f /src
parentaf7cc3c3a5f3b42050df111231b7f0ed298ce6d9 (diff)
Guard against attempting to creating out-of-range spans in macOS File… (#317)
* Guard against attempting to creating out-of-range spans in macOS FileSystemWatcher * Only slice out the root watch directory from path iff it is actually the first part of the path
Diffstat (limited to 'src')
-rw-r--r--src/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs b/src/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs
index a42e637ca3..cd124256af 100644
--- a/src/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs
+++ b/src/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs
@@ -435,7 +435,9 @@ namespace System.IO
// The base FileSystemWatcher does a match check against the relative path before combining with
// the root dir; however, null is special cased to signify the root dir, so check if we should use that.
ReadOnlySpan<char> relativePath = ReadOnlySpan<char>.Empty;
- if (!path.Equals(_fullDirectory, StringComparison.OrdinalIgnoreCase))
+ if (!path.Equals(_fullDirectory, StringComparison.OrdinalIgnoreCase)
+ && path.Length >= _fullDirectory.Length
+ && _fullDirectory.AsSpan().Equals(path.Slice(_fullDirectory.Length), StringComparison.OrdinalIgnoreCase))
{
// Remove the root directory to get the relative path
relativePath = path.Slice(_fullDirectory.Length);
@@ -479,9 +481,18 @@ namespace System.IO
else
{
// Remove the base directory prefix and add the paired event to the list of
- // events to skip and notify the user of the rename
- ReadOnlySpan<char> newPathRelativeName = events[pairedId].Span.Slice(_fullDirectory.Length);
- watcher.NotifyRenameEventArgs(WatcherChangeTypes.Renamed, newPathRelativeName, relativePath);
+ // events to skip and notify the user of the rename
+ if (events[pairedId].Span.Length >= _fullDirectory.Length
+ && ((ReadOnlySpan<char>) events[pairedId].Span).Equals(_fullDirectory.AsSpan(0, events[pairedId].Span.Length), StringComparison.OrdinalIgnoreCase))
+ {
+ ReadOnlySpan<char> newPathRelativeName = events[pairedId].Span.Slice(_fullDirectory.Length);
+ watcher.NotifyRenameEventArgs(WatcherChangeTypes.Renamed, newPathRelativeName, relativePath);
+ }
+ else
+ {
+ //if the base directory prefix isn't there, just use the full absolute path
+ watcher.NotifyRenameEventArgs(WatcherChangeTypes.Renamed, events[pairedId].Span, relativePath);
+ }
// Create a new list, if necessary, and add the event
if (handledRenameEvents == null)