Skip to content

Commit 34a562b

Browse files
authored
Merge pull request #57 from Microsoft/develop
Fix access violation when no query provider
2 parents 8619e96 + 3d4bdd6 commit 34a562b

File tree

15 files changed

+105
-90
lines changed

15 files changed

+105
-90
lines changed

docker/Tests/vswhere.tests.ps1

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,41 @@ Describe 'vswhere' {
1010
[System.Globalization.CultureInfo]::CurrentUICulture = $enu
1111
}
1212

13+
Context '(query provider not registered)' {
14+
BeforeAll {
15+
Start-Process -Wait -FilePath C:\Windows\SysWOW64\regsvr32.exe -ArgumentList @(
16+
'/s',
17+
'/u',
18+
'C:\Downloads\Microsoft.VisualStudio.Setup.Configuration.Native\tools\x86\Microsoft.VisualStudio.Setup.Configuration.Native.dll'
19+
)
20+
}
21+
22+
AfterAll {
23+
Start-Process -Wait -FilePath C:\Windows\SysWOW64\regsvr32.exe -ArgumentList @(
24+
'/s',
25+
'C:\Downloads\Microsoft.VisualStudio.Setup.Configuration.Native\tools\x86\Microsoft.VisualStudio.Setup.Configuration.Native.dll'
26+
)
27+
}
28+
29+
It 'header contains no query version' {
30+
$output = C:\bin\vswhere.exe
31+
$output[0] | Should Match 'Visual Studio Locator version \d+\.\d+\.\d+'
32+
$output[0] | Should Not Match '\[query version \d+\.\d+.*\]'
33+
}
34+
35+
It 'returns 0 instances' {
36+
$instances = C:\bin\vswhere.exe -format json | ConvertFrom-Json
37+
$instances.Count | Should Be 0
38+
}
39+
}
40+
1341
Context '(no arguments)' {
42+
It 'header contains no query version' {
43+
$output = C:\bin\vswhere.exe
44+
$output[0] | Should Match 'Visual Studio Locator version \d+\.\d+\.\d+'
45+
$output[0] | Should Match '\[query version \d+\.\d+.*\]'
46+
}
47+
1448
It 'returns 2 instances using "text"' {
1549
$instanceIds = C:\bin\vswhere.exe | Select-String 'instanceId: \w+'
1650
$instanceIds.Count | Should Be 2
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
using namespace std;
99

10-
void Module::FromIUnknown(_In_ const IUnknown* pUnk) noexcept
10+
void Module::FromIUnknown(_In_opt_ const IUnknown* pUnk) noexcept
1111
{
1212
typedef struct IUnknownVtbl
1313
{
@@ -16,8 +16,11 @@ void Module::FromIUnknown(_In_ const IUnknown* pUnk) noexcept
1616
ULONG(STDMETHODCALLTYPE *Release)(ISetupConfiguration*);
1717
} IUnknownVtbl;
1818

19-
auto pVtbl = reinterpret_cast<const IUnknownVtbl*>(pUnk);
20-
::GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, reinterpret_cast<LPCWSTR>(pVtbl->QueryInterface), &m_hModule);
19+
if (pUnk)
20+
{
21+
auto pVtbl = reinterpret_cast<const IUnknownVtbl*>(pUnk);
22+
::GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, reinterpret_cast<LPCWSTR>(pVtbl->QueryInterface), &m_hModule);
23+
}
2124
}
2225

2326
const wstring& Module::get_Path() noexcept
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class Module
2828
}
2929
}
3030

31-
// Avoid throwing non-catastrphic exceptions since information is for diagnostics only.
32-
void FromIUnknown(_In_ const IUnknown* pUnk) noexcept;
31+
// Avoid throwing non-catastrophic exceptions since information is for diagnostics only.
32+
void FromIUnknown(_In_opt_ const IUnknown* pUnk) noexcept;
3333
const std::wstring& get_Path() noexcept;
3434
const std::wstring& get_FileVersion() noexcept;
3535

src/vswhere.lib/stdafx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ _COM_SMARTPTR_TYPEDEF(ISetupPropertyStore, __uuidof(ISetupPropertyStore));
5757
#include "LegacyInstance.h"
5858
#include "InstanceSelector.h"
5959
#include "JsonFormatter.h"
60+
#include "Module.h"
6061
#include "resource.h"
6162
#include "ResourceManager.h"
6263
#include "SafeArray.h"

src/vswhere.lib/vswhere.lib.vcxproj

Lines changed: 4 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@
1010
<Configuration>Release</Configuration>
1111
<Platform>Win32</Platform>
1212
</ProjectConfiguration>
13-
<ProjectConfiguration Include="Debug|x64">
14-
<Configuration>Debug</Configuration>
15-
<Platform>x64</Platform>
16-
</ProjectConfiguration>
17-
<ProjectConfiguration Include="Release|x64">
18-
<Configuration>Release</Configuration>
19-
<Platform>x64</Platform>
20-
</ProjectConfiguration>
2113
</ItemGroup>
2214
<PropertyGroup Label="Globals">
2315
<ProjectGuid>{4CCF39CB-4794-44E2-AA57-D215F13CF606}</ProjectGuid>
@@ -39,19 +31,6 @@
3931
<WholeProgramOptimization>true</WholeProgramOptimization>
4032
<CharacterSet>Unicode</CharacterSet>
4133
</PropertyGroup>
42-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43-
<ConfigurationType>StaticLibrary</ConfigurationType>
44-
<UseDebugLibraries>true</UseDebugLibraries>
45-
<PlatformToolset>v140</PlatformToolset>
46-
<CharacterSet>Unicode</CharacterSet>
47-
</PropertyGroup>
48-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49-
<ConfigurationType>StaticLibrary</ConfigurationType>
50-
<UseDebugLibraries>false</UseDebugLibraries>
51-
<PlatformToolset>v140</PlatformToolset>
52-
<WholeProgramOptimization>true</WholeProgramOptimization>
53-
<CharacterSet>Unicode</CharacterSet>
54-
</PropertyGroup>
5534
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
5635
<ImportGroup Label="ExtensionSettings">
5736
</ImportGroup>
@@ -65,14 +44,6 @@
6544
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
6645
<Import Project="..\..\inc\Common.props" />
6746
</ImportGroup>
68-
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
69-
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
70-
<Import Project="..\..\inc\Common.Debug.props" />
71-
</ImportGroup>
72-
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
73-
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
74-
<Import Project="..\..\inc\Common.props" />
75-
</ImportGroup>
7647
<PropertyGroup Label="UserMacros" />
7748
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
7849
<TargetName>vswhere</TargetName>
@@ -98,23 +69,9 @@
9869
</ResourceCompile>
9970
<Lib>
10071
<TargetMachine>MachineX86</TargetMachine>
72+
<AdditionalDependencies>shell32.lib;version.lib</AdditionalDependencies>
10173
</Lib>
10274
</ItemDefinitionGroup>
103-
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
104-
<ClCompile>
105-
<PrecompiledHeader>Use</PrecompiledHeader>
106-
<WarningLevel>Level3</WarningLevel>
107-
<Optimization>Disabled</Optimization>
108-
<PreprocessorDefinitions>_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
109-
<SDLCheck>true</SDLCheck>
110-
</ClCompile>
111-
<Link>
112-
<SubSystem>Windows</SubSystem>
113-
</Link>
114-
<ResourceCompile>
115-
<ResourceOutputFileName>$(OutDir)%(Filename).res</ResourceOutputFileName>
116-
</ResourceCompile>
117-
</ItemDefinitionGroup>
11875
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
11976
<ClCompile>
12077
<WarningLevel>Level3</WarningLevel>
@@ -136,27 +93,9 @@
13693
</ResourceCompile>
13794
<Lib>
13895
<TargetMachine>MachineX86</TargetMachine>
96+
<AdditionalDependencies>shell32.lib;version.lib</AdditionalDependencies>
13997
</Lib>
14098
</ItemDefinitionGroup>
141-
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
142-
<ClCompile>
143-
<WarningLevel>Level3</WarningLevel>
144-
<PrecompiledHeader>Use</PrecompiledHeader>
145-
<Optimization>MaxSpeed</Optimization>
146-
<FunctionLevelLinking>true</FunctionLevelLinking>
147-
<IntrinsicFunctions>true</IntrinsicFunctions>
148-
<PreprocessorDefinitions>NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
149-
<SDLCheck>true</SDLCheck>
150-
</ClCompile>
151-
<Link>
152-
<SubSystem>Windows</SubSystem>
153-
<EnableCOMDATFolding>true</EnableCOMDATFolding>
154-
<OptimizeReferences>true</OptimizeReferences>
155-
</Link>
156-
<ResourceCompile>
157-
<ResourceOutputFileName>$(OutDir)%(Filename).res</ResourceOutputFileName>
158-
</ResourceCompile>
159-
</ItemDefinitionGroup>
16099
<ItemGroup>
161100
<ClInclude Include="Console.h" />
162101
<ClInclude Include="CoInitializer.h" />
@@ -169,6 +108,7 @@
169108
<ClInclude Include="JsonFormatter.h" />
170109
<ClInclude Include="LegacyInstance.h" />
171110
<ClInclude Include="LegacyProvider.h" />
111+
<ClInclude Include="Module.h" />
172112
<ClInclude Include="resource.h" />
173113
<ClInclude Include="ResourceManager.h" />
174114
<ClInclude Include="SafeArray.h" />
@@ -189,12 +129,11 @@
189129
<ClCompile Include="JsonFormatter.cpp" />
190130
<ClCompile Include="LegacyInstance.cpp" />
191131
<ClCompile Include="LegacyProvider.cpp" />
132+
<ClCompile Include="Module.cpp" />
192133
<ClCompile Include="ResourceManager.cpp" />
193134
<ClCompile Include="stdafx.cpp">
194135
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
195-
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
196136
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
197-
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
198137
</ClCompile>
199138
<ClCompile Include="TextFormatter.cpp" />
200139
<ClCompile Include="Utilities.cpp" />

src/vswhere.lib/vswhere.lib.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@
7575
<ClInclude Include="LegacyProvider.h">
7676
<Filter>Header Files</Filter>
7777
</ClInclude>
78+
<ClInclude Include="Module.h">
79+
<Filter>Header Files</Filter>
80+
</ClInclude>
7881
</ItemGroup>
7982
<ItemGroup>
8083
<ClCompile Include="stdafx.cpp">
@@ -122,6 +125,9 @@
122125
<ClCompile Include="LegacyProvider.cpp">
123126
<Filter>Source Files</Filter>
124127
</ClCompile>
128+
<ClCompile Include="Module.cpp">
129+
<Filter>Source Files</Filter>
130+
</ClCompile>
125131
</ItemGroup>
126132
<ItemGroup>
127133
<None Include="packages.config" />

src/vswhere/stdafx.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
// Project headers
1919
#include <stdafx.h>
2020
#include <VersionInfo.h>
21-
#include "Module.h"
2221

2322
_COM_SMARTPTR_TYPEDEF(ISetupConfiguration, __uuidof(ISetupConfiguration));
2423
_COM_SMARTPTR_TYPEDEF(ISetupConfiguration2, __uuidof(ISetupConfiguration2));

src/vswhere/vswhere.vcxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
<Link>
6464
<SubSystem>Console</SubSystem>
6565
<GenerateDebugInformation>true</GenerateDebugInformation>
66-
<AdditionalDependencies>version.lib;%(AdditionalDependencies)</AdditionalDependencies>
6766
</Link>
6867
</ItemDefinitionGroup>
6968
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -82,17 +81,14 @@
8281
<EnableCOMDATFolding>true</EnableCOMDATFolding>
8382
<OptimizeReferences>true</OptimizeReferences>
8483
<GenerateDebugInformation>true</GenerateDebugInformation>
85-
<AdditionalDependencies>version.lib;%(AdditionalDependencies)</AdditionalDependencies>
8684
</Link>
8785
</ItemDefinitionGroup>
8886
<ItemGroup>
89-
<ClInclude Include="Module.h" />
9087
<ClInclude Include="resource.h" />
9188
<ClInclude Include="stdafx.h" />
9289
<ClInclude Include="targetver.h" />
9390
</ItemGroup>
9491
<ItemGroup>
95-
<ClCompile Include="Module.cpp" />
9692
<ClCompile Include="Program.cpp" />
9793
<ClCompile Include="stdafx.cpp">
9894
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>

src/vswhere/vswhere.vcxproj.filters

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
<ClInclude Include="resource.h">
2525
<Filter>Header Files</Filter>
2626
</ClInclude>
27-
<ClInclude Include="Module.h">
28-
<Filter>Header Files</Filter>
29-
</ClInclude>
3027
</ItemGroup>
3128
<ItemGroup>
3229
<ClCompile Include="stdafx.cpp">
@@ -35,9 +32,6 @@
3532
<ClCompile Include="Program.cpp">
3633
<Filter>Source Files</Filter>
3734
</ClCompile>
38-
<ClCompile Include="Module.cpp">
39-
<Filter>Source Files</Filter>
40-
</ClCompile>
4135
</ItemGroup>
4236
<ItemGroup>
4337
<None Include="packages.config" />

test/vswhere.test/ModuleTests.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// <copyright file="ModuleTests.cpp" company="Microsoft Corporation">
2+
// Copyright (C) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt in the project root for license information.
4+
// </copyright>
5+
6+
#include "stdafx.h"
7+
8+
using namespace std;
9+
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
10+
11+
// Wrap something cheap and easy to create.
12+
_COM_SMARTPTR_TYPEDEF(IBindCtx, __uuidof(IBindCtx));
13+
14+
TEST_CLASS(ModuleTests)
15+
{
16+
public:
17+
TEST_METHOD(FromIUnknown_NULL)
18+
{
19+
Module sut;
20+
sut.FromIUnknown(NULL);
21+
22+
Assert::AreEqual<size_t>(0, sut.get_Path().length());
23+
Assert::AreEqual<size_t>(0, sut.get_FileVersion().length());
24+
}
25+
26+
TEST_METHOD(FromIUnknown_Not_NULL)
27+
{
28+
IBindCtxPtr binder;
29+
Assert::AreEqual(S_OK, ::CreateBindCtx(0, &binder));
30+
31+
Module sut;
32+
sut.FromIUnknown(binder);
33+
34+
Assert::AreNotEqual<size_t>(0, sut.get_Path().length());
35+
Assert::AreNotEqual<size_t>(0, sut.get_FileVersion().length());
36+
}
37+
};

0 commit comments

Comments
 (0)