Skip to content

Commit 34aa98b

Browse files
committed
add check that path being read from config file is valid
address PR feedback
1 parent 28a9d8a commit 34aa98b

3 files changed

Lines changed: 30 additions & 16 deletions

File tree

build.psm1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ function Start-BuildNativeWindowsBinaries {
172172
[ValidateSet('Debug', 'Release')]
173173
[string]$Configuration = 'Release',
174174

175+
# The `x64_arm` syntax is the build environment for VS2017, `x64` means the host is an x64 machine and will use
176+
# the x64 built tool. The `arm` refers to the target architecture when doing cross compilation.
175177
[ValidateSet('x64', 'x86', 'x64_arm64', 'x64_arm')]
176178
[string]$Arch = 'x64',
177179

src/powershell-native/Install-PowerShellRemoting.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ function Register-WinRmPlugin
7373
"@
7474
$valueString = $regKeyValueFormatString -f $pluginEndpointName, $pluginAbsolutePath, $pluginArchitecture
7575

76-
New-Item $regKey -Force
77-
New-ItemProperty -Path $regKey -Name ConfigXML -Value $valueString
76+
New-Item $regKey -Force > $null
77+
New-ItemProperty -Path $regKey -Name ConfigXML -Value $valueString > $null
7878
}
7979

8080
function Generate-PluginConfigFile

src/powershell-native/nativemsh/pwrshcommon/ConfigFileReader.cpp

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,30 +44,42 @@ namespace NativeMsh
4444
}
4545
else if (*iter == L'p' || *iter == L'P')
4646
{
47-
this->pathToPowerShellAssemblies = this->getValueFromLine(line, psHomeDirTag);
48-
if (this->pathToPowerShellAssemblies.size() > 0) // Found a match
47+
std::wstring psHomeDir = this->getValueFromLine(line, psHomeDirTag);
48+
HANDLE dirHandle = CreateFileW(psHomeDir.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
49+
if (INVALID_HANDLE_VALUE != dirHandle)
4950
{
50-
std::wstring::const_iterator slashIter = this->pathToPowerShellAssemblies.end();
51-
slashIter--;
52-
if (*slashIter != L'\\')
51+
CloseHandle(dirHandle);
52+
this->pathToPowerShellAssemblies = psHomeDir;
53+
if (this->pathToPowerShellAssemblies.size() > 0) // Found a match
5354
{
54-
// Guarantee that there is a '\' at the end of the path
55-
this->pathToPowerShellAssemblies.append(L"\\");
55+
std::wstring::const_iterator slashIter = this->pathToPowerShellAssemblies.end();
56+
slashIter--;
57+
if (*slashIter != L'\\')
58+
{
59+
// Guarantee that there is a '\' at the end of the path
60+
this->pathToPowerShellAssemblies.append(L"\\");
61+
}
5662
}
5763
}
5864
break;
5965
}
6066
else if (*iter == L'c' || *iter == L'C')
6167
{
62-
this->coreClrDirectory = this->getValueFromLine(line, coreClrDirTag);
63-
if (this->coreClrDirectory.size() > 0) // Found a match
68+
std::wstring coreClrDir = this->getValueFromLine(line, coreClrDirTag);
69+
HANDLE dirHandle = CreateFileW(coreClrDir.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
70+
if (INVALID_HANDLE_VALUE != dirHandle)
6471
{
65-
std::wstring::const_iterator slashIter = this->coreClrDirectory.end();
66-
slashIter--;
67-
if (*slashIter != L'\\')
72+
CloseHandle(dirHandle);
73+
this->coreClrDirectory = this->getValueFromLine(line, coreClrDirTag);
74+
if (this->coreClrDirectory.size() > 0) // Found a match
6875
{
69-
// Guarantee that there is a '\' at the end of the path
70-
this->coreClrDirectory.append(L"\\");
76+
std::wstring::const_iterator slashIter = this->coreClrDirectory.end();
77+
slashIter--;
78+
if (*slashIter != L'\\')
79+
{
80+
// Guarantee that there is a '\' at the end of the path
81+
this->coreClrDirectory.append(L"\\");
82+
}
7183
}
7284
}
7385
break;

0 commit comments

Comments
 (0)