Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 688b75c

Browse files
authored
Null Check added to GetFullPath Function in Unix (#15399)
Null Check added to GetFullPath Function in Unix
1 parent ec75534 commit 688b75c

File tree

3 files changed

+3
-37
lines changed

3 files changed

+3
-37
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public static string GetFullPath(string path)
2323
if (path.Length == 0)
2424
throw new ArgumentException(SR.Arg_PathEmpty, nameof(path));
2525

26+
if (path.IndexOf('\0') != -1)
27+
throw new ArgumentException(SR.Argument_InvalidPathChars, nameof(path));
28+
2629
// Expand with current directory if necessary
2730
if (!IsPathRooted(path))
2831
{

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ internal static partial class PathInternal
2222

2323
internal const string ParentDirectoryPrefix = @"../";
2424

25-
/// <summary>Returns a value indicating if the given path contains invalid characters.</summary>
26-
internal static bool HasIllegalCharacters(string path)
27-
{
28-
Debug.Assert(path != null);
29-
return path.IndexOf(InvalidPathChar) >= 0;
30-
}
31-
3225
internal static int GetRootLength(string path)
3326
{
3427
return path.Length > 0 && IsDirectorySeparator(path[0]) ? 1 : 0;

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

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -146,36 +146,6 @@ internal static bool IsExtended(string path)
146146
&& path[3] == '\\';
147147
}
148148

149-
/// <summary>
150-
/// Returns a value indicating if the given path contains invalid characters (", &lt;, &gt;, |
151-
/// NUL, or any ASCII char whose integer representation is in the range of 1 through 31).
152-
/// Does not check for wild card characters ? and *.
153-
/// </summary>
154-
internal static bool HasIllegalCharacters(string path)
155-
{
156-
// This is equivalent to IndexOfAny(InvalidPathChars) >= 0,
157-
// except faster since IndexOfAny grows slower as the input
158-
// array grows larger.
159-
// Since we know that some of the characters we're looking
160-
// for are contiguous in the alphabet-- the path cannot contain
161-
// characters 0-31-- we can optimize this for our specific use
162-
// case and use simple comparison operations.
163-
164-
for (int i = 0; i < path.Length; i++)
165-
{
166-
char c = path[i];
167-
if (c <= '|') // fast path for common case - '|' is highest illegal character
168-
{
169-
if (c <= '\u001f' || c == '|')
170-
{
171-
return true;
172-
}
173-
}
174-
}
175-
176-
return false;
177-
}
178-
179149
/// <summary>
180150
/// Check for known wildcard characters. '*' and '?' are the most common ones.
181151
/// </summary>

0 commit comments

Comments
 (0)