diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2022-06-03 17:49:33 -0500 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2022-06-07 19:44:36 -0500 |
commit | 266b097c0b0a13dd4934f55f61cad62ffcbb953d (patch) | |
tree | 21400e8e1f7a6a5ebbc1abaacb40c472fc0b9fbc /src/libs/dutil/WixToolset.DUtil | |
parent | 584213c5ffeca09b3fe24bd5e92f73fd057ac642 (diff) | |
download | wix-266b097c0b0a13dd4934f55f61cad62ffcbb953d.tar.gz wix-266b097c0b0a13dd4934f55f61cad62ffcbb953d.tar.bz2 wix-266b097c0b0a13dd4934f55f61cad62ffcbb953d.zip |
REG_EXPAND_SZ values are not necessarily a path.
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil')
-rw-r--r-- | src/libs/dutil/WixToolset.DUtil/dutil.vcxproj | 2 | ||||
-rw-r--r-- | src/libs/dutil/WixToolset.DUtil/dutil.vcxproj.filters | 6 | ||||
-rw-r--r-- | src/libs/dutil/WixToolset.DUtil/envutil.cpp | 78 | ||||
-rw-r--r-- | src/libs/dutil/WixToolset.DUtil/inc/dutilsources.h | 1 | ||||
-rw-r--r-- | src/libs/dutil/WixToolset.DUtil/inc/envutil.h | 22 | ||||
-rw-r--r-- | src/libs/dutil/WixToolset.DUtil/pathutil.cpp | 33 | ||||
-rw-r--r-- | src/libs/dutil/WixToolset.DUtil/precomp.h | 1 | ||||
-rw-r--r-- | src/libs/dutil/WixToolset.DUtil/regutil.cpp | 2 |
8 files changed, 113 insertions, 32 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/dutil.vcxproj b/src/libs/dutil/WixToolset.DUtil/dutil.vcxproj index 8a6f3b13..9d057461 100644 --- a/src/libs/dutil/WixToolset.DUtil/dutil.vcxproj +++ b/src/libs/dutil/WixToolset.DUtil/dutil.vcxproj | |||
@@ -65,6 +65,7 @@ | |||
65 | <PrecompiledHeader>Create</PrecompiledHeader> | 65 | <PrecompiledHeader>Create</PrecompiledHeader> |
66 | <DisableSpecificWarnings>4091;4458</DisableSpecificWarnings> | 66 | <DisableSpecificWarnings>4091;4458</DisableSpecificWarnings> |
67 | </ClCompile> | 67 | </ClCompile> |
68 | <ClCompile Include="envutil.cpp" /> | ||
68 | <ClCompile Include="eseutil.cpp" /> | 69 | <ClCompile Include="eseutil.cpp" /> |
69 | <ClCompile Include="file2utl.cpp" /> | 70 | <ClCompile Include="file2utl.cpp" /> |
70 | <ClCompile Include="fileutil.cpp" /> | 71 | <ClCompile Include="fileutil.cpp" /> |
@@ -130,6 +131,7 @@ | |||
130 | <ClInclude Include="inc\dpiutil.h" /> | 131 | <ClInclude Include="inc\dpiutil.h" /> |
131 | <ClInclude Include="inc\dutil.h" /> | 132 | <ClInclude Include="inc\dutil.h" /> |
132 | <ClInclude Include="inc\dutilsources.h" /> | 133 | <ClInclude Include="inc\dutilsources.h" /> |
134 | <ClInclude Include="inc\envutil.h" /> | ||
133 | <ClInclude Include="inc\eseutil.h" /> | 135 | <ClInclude Include="inc\eseutil.h" /> |
134 | <ClInclude Include="inc\fileutil.h" /> | 136 | <ClInclude Include="inc\fileutil.h" /> |
135 | <ClInclude Include="inc\gdiputil.h" /> | 137 | <ClInclude Include="inc\gdiputil.h" /> |
diff --git a/src/libs/dutil/WixToolset.DUtil/dutil.vcxproj.filters b/src/libs/dutil/WixToolset.DUtil/dutil.vcxproj.filters index dbbe68f4..556468b7 100644 --- a/src/libs/dutil/WixToolset.DUtil/dutil.vcxproj.filters +++ b/src/libs/dutil/WixToolset.DUtil/dutil.vcxproj.filters | |||
@@ -66,6 +66,9 @@ | |||
66 | <ClCompile Include="dutil.cpp"> | 66 | <ClCompile Include="dutil.cpp"> |
67 | <Filter>Source Files</Filter> | 67 | <Filter>Source Files</Filter> |
68 | </ClCompile> | 68 | </ClCompile> |
69 | <ClCompile Include="envutil.cpp"> | ||
70 | <Filter>Source Files</Filter> | ||
71 | </ClCompile> | ||
69 | <ClCompile Include="eseutil.cpp"> | 72 | <ClCompile Include="eseutil.cpp"> |
70 | <Filter>Source Files</Filter> | 73 | <Filter>Source Files</Filter> |
71 | </ClCompile> | 74 | </ClCompile> |
@@ -251,6 +254,9 @@ | |||
251 | <ClInclude Include="inc\dutilsources.h"> | 254 | <ClInclude Include="inc\dutilsources.h"> |
252 | <Filter>Header Files</Filter> | 255 | <Filter>Header Files</Filter> |
253 | </ClInclude> | 256 | </ClInclude> |
257 | <ClInclude Include="inc\envutil.h"> | ||
258 | <Filter>Header Files</Filter> | ||
259 | </ClInclude> | ||
254 | <ClInclude Include="inc\eseutil.h"> | 260 | <ClInclude Include="inc\eseutil.h"> |
255 | <Filter>Header Files</Filter> | 261 | <Filter>Header Files</Filter> |
256 | </ClInclude> | 262 | </ClInclude> |
diff --git a/src/libs/dutil/WixToolset.DUtil/envutil.cpp b/src/libs/dutil/WixToolset.DUtil/envutil.cpp new file mode 100644 index 00000000..aa9da233 --- /dev/null +++ b/src/libs/dutil/WixToolset.DUtil/envutil.cpp | |||
@@ -0,0 +1,78 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | #include "precomp.h" | ||
4 | |||
5 | |||
6 | // Exit macros | ||
7 | #define EnvExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_ENVUTIL, x, s, __VA_ARGS__) | ||
8 | #define EnvExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_ENVUTIL, x, s, __VA_ARGS__) | ||
9 | #define EnvExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_ENVUTIL, x, s, __VA_ARGS__) | ||
10 | #define EnvExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_ENVUTIL, x, s, __VA_ARGS__) | ||
11 | #define EnvExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_ENVUTIL, x, s, __VA_ARGS__) | ||
12 | #define EnvExitWithRootFailure(x, e, s, ...) ExitWithRootFailureSource(DUTIL_SOURCE_ENVUTIL, x, e, s, __VA_ARGS__) | ||
13 | #define EnvExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_ENVUTIL, x, s, __VA_ARGS__) | ||
14 | #define EnvExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_ENVUTIL, p, x, e, s, __VA_ARGS__) | ||
15 | #define EnvExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_ENVUTIL, p, x, s, __VA_ARGS__) | ||
16 | #define EnvExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_ENVUTIL, p, x, e, s, __VA_ARGS__) | ||
17 | #define EnvExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_ENVUTIL, p, x, s, __VA_ARGS__) | ||
18 | #define EnvExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_ENVUTIL, e, x, s, __VA_ARGS__) | ||
19 | #define EnvExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_ENVUTIL, g, x, s, __VA_ARGS__) | ||
20 | |||
21 | #define ENV_GOOD_ENOUGH 64 | ||
22 | |||
23 | DAPI_(HRESULT) EnvExpandEnvironmentStrings( | ||
24 | __in LPCWSTR wzSource, | ||
25 | __out LPWSTR* psczExpanded, | ||
26 | __out_opt SIZE_T* pcchExpanded | ||
27 | ) | ||
28 | { | ||
29 | HRESULT hr = S_OK; | ||
30 | DWORD cch = 0; | ||
31 | DWORD cchExpanded = 0; | ||
32 | SIZE_T cchMax = 0; | ||
33 | |||
34 | if (*psczExpanded) | ||
35 | { | ||
36 | hr = StrMaxLength(*psczExpanded, &cchMax); | ||
37 | EnvExitOnFailure(hr, "Failed to get max length of input buffer."); | ||
38 | |||
39 | cchExpanded = (DWORD)min(DWORD_MAX, cchMax); | ||
40 | } | ||
41 | else | ||
42 | { | ||
43 | cchExpanded = ENV_GOOD_ENOUGH; | ||
44 | |||
45 | hr = StrAlloc(psczExpanded, cchExpanded); | ||
46 | EnvExitOnFailure(hr, "Failed to allocate space for expanded path."); | ||
47 | } | ||
48 | |||
49 | cch = ::ExpandEnvironmentStringsW(wzSource, *psczExpanded, cchExpanded); | ||
50 | if (!cch) | ||
51 | { | ||
52 | EnvExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzSource); | ||
53 | } | ||
54 | else if (cchExpanded < cch) | ||
55 | { | ||
56 | cchExpanded = cch; | ||
57 | hr = StrAlloc(psczExpanded, cchExpanded); | ||
58 | EnvExitOnFailure(hr, "Failed to re-allocate more space for expanded path."); | ||
59 | |||
60 | cch = ::ExpandEnvironmentStringsW(wzSource, *psczExpanded, cchExpanded); | ||
61 | if (!cch) | ||
62 | { | ||
63 | EnvExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzSource); | ||
64 | } | ||
65 | else if (cchExpanded < cch) | ||
66 | { | ||
67 | EnvExitWithRootFailure(hr, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), "Failed to allocate buffer for expanded string."); | ||
68 | } | ||
69 | } | ||
70 | |||
71 | if (pcchExpanded) | ||
72 | { | ||
73 | *pcchExpanded = cch; | ||
74 | } | ||
75 | |||
76 | LExit: | ||
77 | return hr; | ||
78 | } | ||
diff --git a/src/libs/dutil/WixToolset.DUtil/inc/dutilsources.h b/src/libs/dutil/WixToolset.DUtil/inc/dutilsources.h index 6affb392..f1dd5d1a 100644 --- a/src/libs/dutil/WixToolset.DUtil/inc/dutilsources.h +++ b/src/libs/dutil/WixToolset.DUtil/inc/dutilsources.h | |||
@@ -62,6 +62,7 @@ typedef enum DUTIL_SOURCE | |||
62 | DUTIL_SOURCE_XMLUTIL, | 62 | DUTIL_SOURCE_XMLUTIL, |
63 | DUTIL_SOURCE_VERUTIL, | 63 | DUTIL_SOURCE_VERUTIL, |
64 | DUTIL_SOURCE_WNDUTIL, | 64 | DUTIL_SOURCE_WNDUTIL, |
65 | DUTIL_SOURCE_ENVUTIL, | ||
65 | 66 | ||
66 | DUTIL_SOURCE_EXTERNAL = 256, | 67 | DUTIL_SOURCE_EXTERNAL = 256, |
67 | } DUTIL_SOURCE; | 68 | } DUTIL_SOURCE; |
diff --git a/src/libs/dutil/WixToolset.DUtil/inc/envutil.h b/src/libs/dutil/WixToolset.DUtil/inc/envutil.h new file mode 100644 index 00000000..8491b27b --- /dev/null +++ b/src/libs/dutil/WixToolset.DUtil/inc/envutil.h | |||
@@ -0,0 +1,22 @@ | |||
1 | #pragma once | ||
2 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
3 | |||
4 | |||
5 | #ifdef __cplusplus | ||
6 | extern "C" { | ||
7 | #endif | ||
8 | |||
9 | /******************************************************************** | ||
10 | EnvExpandEnvironmentStrings - Wrapper for ::ExpandEnvironmentStrings. | ||
11 | |||
12 | *******************************************************************/ | ||
13 | HRESULT DAPI EnvExpandEnvironmentStrings( | ||
14 | __in LPCWSTR wzSource, | ||
15 | __out LPWSTR* psczExpanded, | ||
16 | __out_opt SIZE_T* pcchExpanded | ||
17 | ); | ||
18 | |||
19 | #ifdef __cplusplus | ||
20 | } | ||
21 | #endif | ||
22 | |||
diff --git a/src/libs/dutil/WixToolset.DUtil/pathutil.cpp b/src/libs/dutil/WixToolset.DUtil/pathutil.cpp index dc33e656..becfc67e 100644 --- a/src/libs/dutil/WixToolset.DUtil/pathutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/pathutil.cpp | |||
@@ -181,10 +181,8 @@ DAPI_(HRESULT) PathExpand( | |||
181 | Assert(wzRelativePath); | 181 | Assert(wzRelativePath); |
182 | 182 | ||
183 | HRESULT hr = S_OK; | 183 | HRESULT hr = S_OK; |
184 | DWORD cch = 0; | ||
185 | LPWSTR sczExpandedPath = NULL; | 184 | LPWSTR sczExpandedPath = NULL; |
186 | SIZE_T cchWritten = 0; | 185 | SIZE_T cchWritten = 0; |
187 | DWORD cchExpandedPath = 0; | ||
188 | LPWSTR sczFullPath = NULL; | 186 | LPWSTR sczFullPath = NULL; |
189 | DWORD dwPrefixFlags = 0; | 187 | DWORD dwPrefixFlags = 0; |
190 | 188 | ||
@@ -193,35 +191,8 @@ DAPI_(HRESULT) PathExpand( | |||
193 | // | 191 | // |
194 | if (dwResolveFlags & PATH_EXPAND_ENVIRONMENT) | 192 | if (dwResolveFlags & PATH_EXPAND_ENVIRONMENT) |
195 | { | 193 | { |
196 | cchExpandedPath = PATH_GOOD_ENOUGH; | 194 | hr = EnvExpandEnvironmentStrings(wzRelativePath, &sczExpandedPath, &cchWritten); |
197 | 195 | PathExitOnFailure(hr, "Failed to expand environment variables in string: %ls", wzRelativePath); | |
198 | hr = StrAlloc(&sczExpandedPath, cchExpandedPath); | ||
199 | PathExitOnFailure(hr, "Failed to allocate space for expanded path."); | ||
200 | |||
201 | cch = ::ExpandEnvironmentStringsW(wzRelativePath, sczExpandedPath, cchExpandedPath); | ||
202 | if (0 == cch) | ||
203 | { | ||
204 | PathExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath); | ||
205 | } | ||
206 | else if (cchExpandedPath < cch) | ||
207 | { | ||
208 | cchExpandedPath = cch; | ||
209 | hr = StrAlloc(&sczExpandedPath, cchExpandedPath); | ||
210 | PathExitOnFailure(hr, "Failed to re-allocate more space for expanded path."); | ||
211 | |||
212 | cch = ::ExpandEnvironmentStringsW(wzRelativePath, sczExpandedPath, cchExpandedPath); | ||
213 | if (0 == cch) | ||
214 | { | ||
215 | PathExitWithLastError(hr, "Failed to expand environment variables in string: %ls", wzRelativePath); | ||
216 | } | ||
217 | else if (cchExpandedPath < cch) | ||
218 | { | ||
219 | hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); | ||
220 | PathExitOnRootFailure(hr, "Failed to allocate buffer for expanded path."); | ||
221 | } | ||
222 | } | ||
223 | |||
224 | cchWritten = cch; | ||
225 | } | 196 | } |
226 | 197 | ||
227 | // | 198 | // |
diff --git a/src/libs/dutil/WixToolset.DUtil/precomp.h b/src/libs/dutil/WixToolset.DUtil/precomp.h index 902fe3e3..c9e4f74a 100644 --- a/src/libs/dutil/WixToolset.DUtil/precomp.h +++ b/src/libs/dutil/WixToolset.DUtil/precomp.h | |||
@@ -52,6 +52,7 @@ | |||
52 | #include "cabutil.h" | 52 | #include "cabutil.h" |
53 | #include "conutil.h" | 53 | #include "conutil.h" |
54 | #include "cryputil.h" | 54 | #include "cryputil.h" |
55 | #include "envutil.h" | ||
55 | #include "eseutil.h" | 56 | #include "eseutil.h" |
56 | #include "dirutil.h" | 57 | #include "dirutil.h" |
57 | #include "dlutil.h" | 58 | #include "dlutil.h" |
diff --git a/src/libs/dutil/WixToolset.DUtil/regutil.cpp b/src/libs/dutil/WixToolset.DUtil/regutil.cpp index 584966ed..9a1b9ced 100644 --- a/src/libs/dutil/WixToolset.DUtil/regutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/regutil.cpp | |||
@@ -444,7 +444,7 @@ DAPI_(HRESULT) RegReadValue( | |||
444 | if (fExpand && SUCCEEDED(hr) && REG_EXPAND_SZ == *pdwType) | 444 | if (fExpand && SUCCEEDED(hr) && REG_EXPAND_SZ == *pdwType) |
445 | { | 445 | { |
446 | LPWSTR sczValue = reinterpret_cast<LPWSTR>(*ppbBuffer); | 446 | LPWSTR sczValue = reinterpret_cast<LPWSTR>(*ppbBuffer); |
447 | hr = PathExpand(&sczExpand, sczValue, PATH_EXPAND_ENVIRONMENT); | 447 | hr = EnvExpandEnvironmentStrings(sczValue, &sczExpand, NULL); |
448 | RegExitOnFailure(hr, "Failed to expand registry value: %ls", sczValue); | 448 | RegExitOnFailure(hr, "Failed to expand registry value: %ls", sczValue); |
449 | 449 | ||
450 | *ppbBuffer = reinterpret_cast<LPBYTE>(sczExpand); | 450 | *ppbBuffer = reinterpret_cast<LPBYTE>(sczExpand); |