Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process: throw ArgumentNullException when ArgumentList contains a null. #59562

Merged
merged 3 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@
<data name="ArgumentAndArgumentListInitialized" xml:space="preserve">
<value>Only one of Arguments or ArgumentList may be used.</value>
</data>
<data name="ArgumentListMayNotContainNull" xml:space="preserve">
<value>ArgumentList may not contain null.</value>
</data>
<data name="KillEntireProcessTree_DisallowedBecauseTreeContainsCallingProcess" xml:space="preserve">
<value>Cannot be used to terminate a process tree containing the calling process.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,17 @@ public bool Start()
{
throw new InvalidOperationException(SR.ArgumentAndArgumentListInitialized);
}
if (startInfo.HasArgumentList)
{
int argumentCount = startInfo.ArgumentList.Count;
for (int i = 0; i < argumentCount; i++)
{
if (startInfo.ArgumentList[i] is null)
{
throw new ArgumentNullException("item", SR.ArgumentListMayNotContainNull);
}
}
}

//Cannot start a new process and store its handle if the object has been disposed, since finalization has been suppressed.
CheckDisposed();
Expand Down
12 changes: 12 additions & 0 deletions src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2214,6 +2214,18 @@ public void StartProcessWithArgumentList()
}
}

[Fact]
public void ArgumentListArgumentNullThrowsOnStart()
{
ProcessStartInfo psi = new ProcessStartInfo(GetCurrentProcessName());
psi.ArgumentList.Add(null);

Process testProcess = CreateProcess();
testProcess.StartInfo = psi;

AssertExtensions.Throws<ArgumentNullException>("item", () => testProcess.Start());
}

[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
[PlatformSpecific(TestPlatforms.Windows)]
public void StartProcessWithSameArgumentList()
Expand Down