diff --git a/scripts/deploy-ftp.ps1 b/scripts/deploy-ftp.ps1 index fc554c4..0104a80 100644 --- a/scripts/deploy-ftp.ps1 +++ b/scripts/deploy-ftp.ps1 @@ -47,19 +47,21 @@ function Assert-Tool { Assert-Tool "dotnet" Assert-Tool $WinScpPath -function Read-PlainOrPrompt([string]$Value, [string]$Prompt, [switch]$Secure) { +function Read-PlainOrPrompt([string]$Value, [string]$Prompt, [bool]$Secure = $false) { if ($Value) { return $Value } if ($Secure) { $secure = Read-Host -Prompt $Prompt -AsSecureString - return [Runtime.InteropServices.Marshal]::PtrToStringUni( - [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secure) - ) + $ptr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secure) + try { return [Runtime.InteropServices.Marshal]::PtrToStringUni($ptr) } + finally { + if ($ptr -ne [IntPtr]::Zero) { [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($ptr) } + } } return Read-Host -Prompt $Prompt } -$FtpPassword = Read-PlainOrPrompt $FtpPassword "FTP password" -Secure -$WinRmCredentialPass = Read-PlainOrPrompt $WinRmCredentialPass "WinRM password" -Secure +$FtpPassword = Read-PlainOrPrompt $FtpPassword "FTP password" $true +$WinRmCredentialPass = Read-PlainOrPrompt $WinRmCredentialPass "WinRM password" $true Write-Host "1) Publishing..." -ForegroundColor Cyan New-Item -ItemType Directory -Force -Path $PublishDir | Out-Null