Skip to content

[PostgreSql] Please use PtrToStringBSTR instead of PtrToStringAuto for secure string decrytion #12956

Closed
@dolauli

Description

@dolauli

Description

The issue happens in PowerShell 7.* in Linux/MacOS. The root cause is there is breaking change for the API PtrToStringAuto.
To workaround the issue, please follow the sample below to decrpyt secure string.

$psTxt = . "$PSScriptRoot/../utils/Unprotect-SecureString.ps1" $PSBoundParameters['Password']

Source code of Unprotect-SecureSting.ps1

#This script converts securestring to plaintext

param(
    [Parameter(Mandatory, ValueFromPipeline)]
    [System.Security.SecureString]
    ${SecureString}
)

$ssPtr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecureString)
try {
    $plaintext = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($ssPtr)
} finally {
    [System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($ssPtr)
}

return $plaintext

https://github.com/Azure/azure-powershell/pull/12842/files

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions