Skip to content

Fix ConvertTo-SecureString with key regression due to .NET breaking change#16068

Merged
daxian-dbw merged 7 commits intoPowerShell:masterfrom
PaulHigin:fix-dotnet-break
Sep 9, 2021
Merged

Fix ConvertTo-SecureString with key regression due to .NET breaking change#16068
daxian-dbw merged 7 commits intoPowerShell:masterfrom
PaulHigin:fix-dotnet-break

Conversation

@PaulHigin
Copy link
Copy Markdown
Contributor

@PaulHigin PaulHigin commented Sep 8, 2021

PR Summary

This PR fixes a regression in ConvertTo-SecureString found and reported by this Issue.
Fix #16047.

PR Context

This regression was caused by the change of behavior in the .NET CryptoStream.Read() method. Previously, the Read method would synchronously read entire stream contents into the provided buffer, until the buffer was filled or the stream ended. It was recently changed to read available data and return before the buffer is filled or the stream ended, breaking the existing code which would now read only partial stream contents.

Instead of performing multiple reads to ensure all stream content is obtained, this change uses an alternative common pattern to copy entire stream contents. It also takes care to dispose all disposable objects and zero out clear-text buffers.

PR Checklist

Comment thread src/System.Management.Automation/security/SecureStringHelper.cs Outdated
Comment thread src/System.Management.Automation/security/SecureStringHelper.cs Outdated
Comment thread src/System.Management.Automation/security/SecureStringHelper.cs Outdated
PaulHigin and others added 3 commits September 8, 2021 16:04
@PaulHigin
Copy link
Copy Markdown
Contributor Author

@rjmholt Thanks for the review!

Comment thread src/System.Management.Automation/security/SecureStringHelper.cs Outdated
Comment thread src/System.Management.Automation/security/SecureStringHelper.cs Outdated
Comment thread src/System.Management.Automation/security/SecureStringHelper.cs
Comment thread src/System.Management.Automation/security/SecureStringHelper.cs
Comment thread src/System.Management.Automation/security/SecureStringHelper.cs Outdated
@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Sep 9, 2021
@daxian-dbw daxian-dbw merged commit 0d7ba2f into PowerShell:master Sep 9, 2021
@iSazonov iSazonov added this to the 7.2.0-rc.1 milestone Sep 9, 2021
@ghost
Copy link
Copy Markdown

ghost commented Dec 16, 2021

🎉v7.3.0-preview.1 has been released which incorporates this pull request.:tada:

Handy links:

TrapGodBrim pushed a commit to TrapGodBrim/PowerShell that referenced this pull request Jan 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport-7.2.x-Done CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ConvertTo-SecureString truncates to multiples of 8 characters

6 participants