Fix the memset issue related to default cmd option (#223)

Fix the memset issue related to default cmd option
This commit is contained in:
bagajjal 2017-10-16 19:03:02 -07:00 committed by Yanbing
parent 97959981f6
commit 9555bd9e87
2 changed files with 19 additions and 14 deletions

View File

@ -1210,6 +1210,7 @@ get_default_shell_path()
memset(tmp, 0, PATH_MAX + 1);
memset(default_shell_path, 0, _countof(default_shell_path));
memset(default_shell_cmd_option, 0, _countof(default_shell_cmd_option));
if ((RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\OpenSSH", 0, mask, &reg_key) == ERROR_SUCCESS) &&
(RegQueryValueExW(reg_key, L"DefaultShell", 0, NULL, (LPBYTE)tmp, &tmp_len) == ERROR_SUCCESS) &&
@ -1246,8 +1247,7 @@ get_default_shell_path()
/* if default shell is not configured then use cmd.exe as the default shell */
if (!is_default_shell_configured)
wcscat_s(default_shell_path, _countof(default_shell_path), cmd_exe_path);
memset(default_shell_cmd_option, 0, _countof(default_shell_cmd_option));
if (!default_shell_cmd_option[0]) {
if (wcsstr(default_shell_path, L"cmd.exe") || wcsstr(default_shell_path, L"powershell.exe"))
wcscat_s(default_shell_cmd_option, _countof(default_shell_cmd_option), L" /c ");

View File

@ -67,18 +67,22 @@ Describe "E2E scenarios for ssh client" -Tags "CI" {
Options = '-i $identifyFile -l $($server.localAdminUserName)'
}
)#>
$defaultRegistryPath = "HKLM:\Software\OpenSSH"
$registryKeyName = "DefaultShell"
$dfltShellRegPath = "HKLM:\Software\OpenSSH"
$dfltShellRegKeyName = "DefaultShell"
$dfltShellCmdOptionRegKeyName = "DefaultShellCommandOption"
function ConfigureDefaultShell {
param([string]$default_shell_path)
param
(
[string] $default_shell_path,
[string] $default_shell_cmd_option_val
)
if (!(Test-Path $defaultRegistryPath)) {
New-Item -Path $defaultRegistryPath -Force | Out-Null
New-ItemProperty -Path $defaultRegistryPath -Name $registryKeyName -Value $default_shell_path -PropertyType String -Force
} else {
New-ItemProperty -Path $defaultRegistryPath -Name $registryKeyName -Value $default_shell_path -PropertyType String -Force
if (!(Test-Path $dfltShellRegPath)) {
New-Item -Path $dfltShellRegPath -Force | Out-Null
}
New-ItemProperty -Path $dfltShellRegPath -Name $dfltShellRegKeyName -Value $default_shell_path -PropertyType String -Force
New-ItemProperty -Path $dfltShellRegPath -Name $dfltShellCmdOptionRegKeyName -Value $default_shell_cmd_option_val -PropertyType String -Force
}
}
@ -149,13 +153,14 @@ Describe "E2E scenarios for ssh client" -Tags "CI" {
BeforeAll {$tI=1}
AfterAll{$tC++}
AfterEach {
Remove-ItemProperty -Name $registryKeyName -Path $defaultRegistryPath -ErrorAction SilentlyContinue
Remove-ItemProperty -Path $dfltShellRegPath -Name $dfltShellRegKeyName -ErrorAction SilentlyContinue
Remove-ItemProperty -Path $dfltShellRegPath -Name $dfltShellCmdOptionRegKeyName -ErrorAction SilentlyContinue
}
It "$tC.$tI - default shell as powershell" {
$shell_path = (Get-Command powershell.exe -ErrorAction SilentlyContinue).path
if($shell_path -ne $null) {
ConfigureDefaultShell -default_shell_path $shell_path
ConfigureDefaultShell -default_shell_path $shell_path -default_shell_cmd_option_val "/c"
$o = ssh test_target Write-Output 1234
$o | Should Be "1234"
@ -165,7 +170,7 @@ Describe "E2E scenarios for ssh client" -Tags "CI" {
It "$tC.$tI - default shell as cmd" {
$shell_path = (Get-Command cmd.exe -ErrorAction SilentlyContinue).path
if($shell_path -ne $null) {
ConfigureDefaultShell -default_shell_path $shell_path
ConfigureDefaultShell -default_shell_path $shell_path -default_shell_cmd_option_val "/c"
$o = ssh test_target where cmd
$o | Should Contain "cmd"
@ -232,7 +237,7 @@ Describe "E2E scenarios for ssh client" -Tags "CI" {
$logFile | Should Contain "[::1]"
}
}
<#Context "Key is not secured in ssh-agent on server" {