Fix for SSH remoting when banner is enabled on SSHD endpoint (#16205)

This commit is contained in:
Paul Higinbotham
2021-10-28 10:39:55 -07:00
committed by GitHub
parent ffd06eb8ed
commit bd4e5598ce
2 changed files with 37 additions and 1 deletions
@@ -23,6 +23,7 @@ namespace System.Management.Automation
internal const string EngineSource = "PSEngine";
internal const string PSNativeCommandArgumentPassingFeatureName = "PSNativeCommandArgumentPassing";
internal const string PSNativeCommandErrorActionPreferenceFeatureName = "PSNativeCommandErrorActionPreference";
internal const string PSRemotingSSHTransportErrorHandling = "PSRemotingSSHTransportErrorHandling";
internal const string PSCleanBlockFeatureName = "PSCleanBlock";
#endregion
@@ -127,6 +128,9 @@ namespace System.Management.Automation
new ExperimentalFeature(
name: PSNativeCommandErrorActionPreferenceFeatureName,
description: "Native commands with non-zero exit codes issue errors according to $ErrorActionPreference when $PSNativeCommandUseErrorActionPreference is $true"),
new ExperimentalFeature(
name: PSRemotingSSHTransportErrorHandling,
description: "Removes the SSH remoting transport stdErr stream message handling as terminating errors, and instead just writes error messages to console."),
new ExperimentalFeature(
name: PSCleanBlockFeatureName,
description: "Add support of a 'Clean' block to functions and script cmdlets for easy resource cleanup"),
@@ -1762,7 +1762,39 @@ namespace System.Management.Automation.Remoting.Client
while (true)
{
string error = ReadError(reader);
string error;
if (ExperimentalFeature.IsEnabled(ExperimentalFeature.PSRemotingSSHTransportErrorHandling))
{
// Blocking read from StdError stream
error = reader.ReadLine();
if (error == null)
{
// Stream is closed unexpectedly.
throw new PSInvalidOperationException(RemotingErrorIdStrings.SSHAbruptlyTerminated);
}
if (error.Length == 0)
{
// Ignore
continue;
}
try
{
// Messages in error stream from ssh are unreliable, and may just be warnings or
// banner text.
// So just report the messages but don't act on them.
System.Console.WriteLine(error);
}
catch (IOException)
{ }
continue;
}
error = ReadError(reader);
if (error.Length == 0)
{