Skip to content

Commit

Permalink
Add lock and null check to remoting internals (PowerShell#16542) (Pow…
Browse files Browse the repository at this point in the history
…erShell#16683)

* fix crash Copy-Item to remote session (PowerShell#16542)

* update comments

* remove lock (PowerShell#16542)

Co-authored-by: Sergey Zalyadeev <sergey.zalyadeev@cayosoft.com>
  • Loading branch information
2 people authored and TrapGodBrim committed Jan 19, 2022
1 parent 5249ab6 commit 450953d
Showing 1 changed file with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,29 @@ internal void Clear()
lock (_readSyncObject)
{
priorityType = DataPriorityType.Default;

// send data from which ever stream that has data directly.
// Send data from which ever stream that has data directly.
byte[] result = null;
result = _dataToBeSent[(int)DataPriorityType.PromptResponse].ReadOrRegisterCallback(_onSendCollectionDataAvailable);
priorityType = DataPriorityType.PromptResponse;
SerializedDataStream promptDataToBeSent = _dataToBeSent[(int)DataPriorityType.PromptResponse];
if (promptDataToBeSent is not null)
{
result = promptDataToBeSent.ReadOrRegisterCallback(_onSendCollectionDataAvailable);
priorityType = DataPriorityType.PromptResponse;
}

if (result == null)
{
result = _dataToBeSent[(int)DataPriorityType.Default].ReadOrRegisterCallback(_onSendCollectionDataAvailable);
priorityType = DataPriorityType.Default;
SerializedDataStream defaultDataToBeSent = _dataToBeSent[(int)DataPriorityType.Default];
if (defaultDataToBeSent is not null)
{
result = defaultDataToBeSent.ReadOrRegisterCallback(_onSendCollectionDataAvailable);
priorityType = DataPriorityType.Default;
}
}
// no data to return..so register the callback.

// No data to return..so register the callback.
if (result == null)
{
// register callback.
// Register callback.
_onDataAvailableCallback = callback;
}

Expand Down

0 comments on commit 450953d

Please sign in to comment.