-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Skip null data (fix NRE) in output data received handler #11448
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
Merged
daxian-dbw
merged 9 commits into
PowerShell:master
from
iSazonov:remoting-nre-in-handler
Jan 10, 2020
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5335323
Skip null data in output data received handler
iSazonov a087950
Move fix to GetMessageGuid()
iSazonov c893e62
Refactor GetMessageGuid() to avoid extra allocations
iSazonov 69522d5
Address feedback
iSazonov bedfef8
Implement IsCommandMessage()
iSazonov 0cc9c70
Remove comment
iSazonov 7e2a097
Move if block out of try-catch
iSazonov 20edc1e
Implement IsSessionMessage()
iSazonov 6f49088
Inline IsSessionMessage()
iSazonov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -650,7 +650,7 @@ internal override void Dispose(bool isDisposing) | |
| { | ||
SteveL-MSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Object already disposed. | ||
| } | ||
|
|
||
| _commandMessageQueue.Dispose(); | ||
| } | ||
| } | ||
|
|
@@ -741,41 +741,26 @@ private void ProcessMessageProc(object state) | |
| } | ||
| } | ||
|
|
||
| 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 | ||
|
|
||
| #region Event Handlers | ||
|
|
||
| private const string SESSIONDMESSAGETAG = "PSGuid='00000000-0000-0000-0000-000000000000'"; | ||
|
|
||
| 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 | ||
| { | ||
| // Route protocol message based on whether it is a session or command message. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move string null/empty check to here.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the explicit check. |
||
| // Session messages have empty Guid values. | ||
| if (Guid.Equals(GetMessageGuid(data), Guid.Empty)) | ||
| if (data.IndexOf(SESSIONDMESSAGETAG, StringComparison.OrdinalIgnoreCase) > -1) | ||
| { | ||
| // Session message | ||
| _sessionMessageQueue.Add(data); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.