[release/v7.4.21] Fix `FileOnlyEntry` crashing on older versions of Windows by adityapatwardhan · Pull Request #28043 · PowerShell/PowerShell · GitHub
Skip to content
Open
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
91 changes: 47 additions & 44 deletions src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@
// improve startup performance.
}

uint exitCode = ExitCodeSuccess;

Thread.CurrentThread.Name = "ConsoleHost main thread";

try
Expand All @@ -185,7 +183,7 @@
// or start up the engine and retrieve the information via $psversiontable.GitCommitId
// but this returns the semantic version and avoids executing a script
s_theConsoleHost.UI.WriteLine($"PowerShell {PSVersionInfo.GitCommitId}");
return 0;
return ExitCodeSuccess;
}

// Servermode parameter validation check.
Expand Down Expand Up @@ -216,6 +214,14 @@
return ExitCodeBadCommandLineParameter;
}

if (serverModeCount is 1 && CommandLineParameterParser.IsFileOnlyEntryEnabled)
{
// User facing error message should already be written by the parser,
// so just trace and exit.
s_tracer.TraceError("Server mode cannot be specified when FileOnlyEntry policy is in place.");
return ExitCodeBadCommandLineParameter;
}

#if !UNIX
TaskbarJumpList.CreateRunAsAdministratorJumpList();
#endif
Expand All @@ -230,9 +236,10 @@
configurationName: null,
configurationFile: s_cpp.ConfigurationFile,
combineErrOutStream: false);
exitCode = 0;
return ExitCodeSuccess;
}
else if (s_cpp.SSHServerMode)

if (s_cpp.SSHServerMode)
{
ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry("SSHServer", s_cpp.ParametersUsedAsDouble);
ProfileOptimization.StartProfile("StartupProfileData-SSHServerMode");
Expand All @@ -242,18 +249,20 @@
configurationName: null,
configurationFile: s_cpp.ConfigurationFile,
combineErrOutStream: true);
exitCode = 0;
return ExitCodeSuccess;
}
else if (s_cpp.NamedPipeServerMode)

if (s_cpp.NamedPipeServerMode)
{
ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry("NamedPipe", s_cpp.ParametersUsedAsDouble);
ProfileOptimization.StartProfile("StartupProfileData-NamedPipeServerMode");
RemoteSessionNamedPipeServer.RunServerMode(
configurationName: s_cpp.ConfigurationName);
exitCode = 0;
return ExitCodeSuccess;
}
#if !UNIX
else if (s_cpp.V2SocketServerMode)

if (s_cpp.V2SocketServerMode)
{
if (s_cpp.Token == null)
{
Expand All @@ -275,52 +284,51 @@
initialCommand: s_cpp.InitialCommand,
configurationName: s_cpp.ConfigurationName,
token: s_cpp.Token,
tokenCreationTime: s_cpp.UTCTimestamp.Value
);
exitCode = 0;
tokenCreationTime: s_cpp.UTCTimestamp.Value);

return ExitCodeSuccess;
}
#endif
else if (s_cpp.SocketServerMode)

if (s_cpp.SocketServerMode)
{
ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry("SocketServerMode", s_cpp.ParametersUsedAsDouble);
ProfileOptimization.StartProfile("StartupProfileData-SocketServerMode");
HyperVSocketMediator.Run(
initialCommand: s_cpp.InitialCommand,
configurationName: s_cpp.ConfigurationName);
exitCode = 0;
return ExitCodeSuccess;
}
else

// Run PowerShell in normal console mode.
if (hostException != null)
{
// Run PowerShell in normal console mode.
if (hostException != null)
{
// Unable to create console host.
throw hostException;
}
// Unable to create console host.
throw hostException;
}

if (LoadPSReadline())
{
ProfileOptimization.StartProfile("StartupProfileData-Interactive");
if (LoadPSReadline())
{
ProfileOptimization.StartProfile("StartupProfileData-Interactive");

if (UpdatesNotification.CanNotifyUpdates)
{
// Start a task in the background to check for the update release.
_ = UpdatesNotification.CheckForUpdates();
}
}
else
if (UpdatesNotification.CanNotifyUpdates)
{
ProfileOptimization.StartProfile("StartupProfileData-NonInteractive");
// Start a task in the background to check for the update release.
_ = UpdatesNotification.CheckForUpdates();
}
}
else
{
ProfileOptimization.StartProfile("StartupProfileData-NonInteractive");
}

s_theConsoleHost.BindBreakHandler();
IsStdOutputRedirected = Console.IsOutputRedirected;
s_theConsoleHost.BindBreakHandler();
IsStdOutputRedirected = Console.IsOutputRedirected;

// Send startup telemetry for ConsoleHost startup
ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry("Normal", s_cpp.ParametersUsedAsDouble);
// Send startup telemetry for ConsoleHost startup
ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry("Normal", s_cpp.ParametersUsedAsDouble);

exitCode = s_theConsoleHost.Run(s_cpp, false);
}
return unchecked((int)s_theConsoleHost.Run(s_cpp, false));
}
finally
{
Expand All @@ -342,11 +350,6 @@
}
#pragma warning restore IDE0031
}

unchecked
{
return (int)exitCode;
}
}

internal static void ParseCommandLine(string[] args)
Expand Down Expand Up @@ -3161,4 +3164,4 @@

internal Collection<CommandParameter> InitialCommandArgs { get; set; }
}
} // namespace
} // namespace

Check failure on line 3167 in src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs

View workflow job for this annotation

GitHub Actions / Build PowerShell

Check failure on line 3167 in src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs

View workflow job for this annotation

GitHub Actions / CodeQL Analysis / Analyze (csharp)

Check failure on line 3167 in src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs

View workflow job for this annotation

GitHub Actions / xUnit Tests / Run xUnit Tests

Check failure on line 3167 in src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs

View workflow job for this annotation

GitHub Actions / Build PowerShell

Check failure on line 3167 in src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs

View workflow job for this annotation

GitHub Actions / xUnit Tests / Run xUnit Tests

Check failure on line 3167 in src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs

View workflow job for this annotation

GitHub Actions / Build PowerShell

Check failure on line 3167 in src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs

View workflow job for this annotation

GitHub Actions / xUnit Tests / Run xUnit Tests

Check failure on line 3167 in src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs

View workflow job for this annotation

GitHub Actions / CodeQL Analysis / Analyze (csharp)

Loading
Loading