Skip null data in output data received handler to fix a NullReferenceException
(#11448)
This commit is contained in:
parent
5ad4d2c399
commit
397756a26f
|
@ -741,41 +741,26 @@ namespace System.Management.Automation.Remoting.Client
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private const string GUIDTAG = "PSGuid='";
|
|
||||||
private const int GUID_STR_LEN = 36; // GUID string: 32 digits plus 4 dashes
|
|
||||||
|
|
||||||
private Guid GetMessageGuid(string data)
|
|
||||||
{
|
|
||||||
// Perform quick scan for data packet for a GUID, ignoring any errors.
|
|
||||||
var iTag = data.IndexOf(GUIDTAG, StringComparison.OrdinalIgnoreCase);
|
|
||||||
if (iTag > -1)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var psGuidString = data.Substring(iTag + GUIDTAG.Length, GUID_STR_LEN);
|
|
||||||
return new Guid(psGuidString);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
// Ignore any malformed packet errors here and return an empty Guid.
|
|
||||||
// Packet errors will be reported later during message processing.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Guid.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Event Handlers
|
#region Event Handlers
|
||||||
|
|
||||||
|
private const string SESSIONDMESSAGETAG = "PSGuid='00000000-0000-0000-0000-000000000000'";
|
||||||
|
|
||||||
protected void HandleOutputDataReceived(string data)
|
protected void HandleOutputDataReceived(string data)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(data))
|
||||||
|
{
|
||||||
|
// A null/empty data string indicates a problem in the transport,
|
||||||
|
// e.g., named pipe emitting a null packet because it closed or some reason.
|
||||||
|
// In this case we simply ignore the packet.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Route protocol message based on whether it is a session or command message.
|
// Route protocol message based on whether it is a session or command message.
|
||||||
// Session messages have empty Guid values.
|
if (data.IndexOf(SESSIONDMESSAGETAG, StringComparison.OrdinalIgnoreCase) > -1)
|
||||||
if (Guid.Equals(GetMessageGuid(data), Guid.Empty))
|
|
||||||
{
|
{
|
||||||
// Session message
|
// Session message
|
||||||
_sessionMessageQueue.Add(data);
|
_sessionMessageQueue.Add(data);
|
||||||
|
|
Loading…
Reference in a new issue