Powershell: PtrToString Behavior Differs on PS 7 Linux vs Windows

Created on 14 Mar 2020  路  1Comment  路  Source: PowerShell/PowerShell

Steps to reproduce

$ss = ConvertTo-SecureString -String 'TestString' -AsPlainText -Force
$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($ss)
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr)

Expected behavior

Should return 'TestString'

Actual behavior

On PS 7 on Linux:

Returns 'T' - Incorrect Behavior.

image

On PS 7 on Windows 10:

Returns 'TestString' - Correct Behavior.

image

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.0
PSEdition                      Core
GitCommitId                    7.0.0
OS                             Linux 4.4.0-19582-Microsoft #1001-Microsoft Thu Mar 06 16:40:00 PST 2020
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0鈥
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

This is a minor issue as the above code can usually be replaced with ConvertFrom-SecureString on PS 7/PS Core 6, but not on PS 5.1.

Issue-Question Resolution-Duplicate

Most helpful comment

This is a duplicate of #12114; for a summary, see https://github.com/PowerShell/PowerShell/issues/12114#issuecomment-598347725

>All comments

This is a duplicate of #12114; for a summary, see https://github.com/PowerShell/PowerShell/issues/12114#issuecomment-598347725

Was this page helpful?
0 / 5 - 0 ratings