Null Check added to GetFullPath Function in Unix (#15399)
authorAnirudh Agnihotry <anirudhagnihotry098@gmail.com>
Thu, 7 Dec 2017 03:16:50 +0000 (19:16 -0800)
committerGitHub <noreply@github.com>
Thu, 7 Dec 2017 03:16:50 +0000 (19:16 -0800)
Null Check added to GetFullPath Function in Unix

src/mscorlib/shared/System/IO/Path.Unix.cs
src/mscorlib/shared/System/IO/PathInternal.Unix.cs
src/mscorlib/shared/System/IO/PathInternal.Windows.cs

index e5be579..1143c05 100644 (file)
@@ -23,6 +23,9 @@ namespace System.IO
             if (path.Length == 0)
                 throw new ArgumentException(SR.Arg_PathEmpty, nameof(path));
 
+            if (path.IndexOf('\0') != -1)
+                throw new ArgumentException(SR.Argument_InvalidPathChars, nameof(path)); 
+            
             // Expand with current directory if necessary
             if (!IsPathRooted(path))
             {
index 1113201..2f65a42 100644 (file)
@@ -22,13 +22,6 @@ namespace System.IO
 
         internal const string ParentDirectoryPrefix = @"../";
 
-        /// <summary>Returns a value indicating if the given path contains invalid characters.</summary>
-        internal static bool HasIllegalCharacters(string path)
-        {
-            Debug.Assert(path != null);
-            return path.IndexOf(InvalidPathChar) >= 0;
-        }
-
         internal static int GetRootLength(string path)
         {
             return path.Length > 0 && IsDirectorySeparator(path[0]) ? 1 : 0;
index 2ab3928..f315f43 100644 (file)
@@ -147,36 +147,6 @@ namespace System.IO
         }
 
         /// <summary>
-        /// Returns a value indicating if the given path contains invalid characters (", &lt;, &gt;, | 
-        /// NUL, or any ASCII char whose integer representation is in the range of 1 through 31).
-        /// Does not check for wild card characters ? and *.
-        /// </summary>
-        internal static bool HasIllegalCharacters(string path)
-        {
-            // This is equivalent to IndexOfAny(InvalidPathChars) >= 0,
-            // except faster since IndexOfAny grows slower as the input
-            // array grows larger.
-            // Since we know that some of the characters we're looking
-            // for are contiguous in the alphabet-- the path cannot contain
-            // characters 0-31-- we can optimize this for our specific use
-            // case and use simple comparison operations.
-
-            for (int i = 0; i < path.Length; i++)
-            {
-                char c = path[i];
-                if (c <= '|') // fast path for common case - '|' is highest illegal character
-                {
-                    if (c <= '\u001f' || c == '|')
-                    {
-                        return true;
-                    }
-                }
-            }
-
-            return false;
-        }
-
-        /// <summary>
         /// Check for known wildcard characters. '*' and '?' are the most common ones.
         /// </summary>
         internal static bool HasWildCardCharacters(string path)