aboutsummaryrefslogtreecommitdiff
path: root/src/burn
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2022-06-03 17:49:15 -0500
committerSean Hall <r.sean.hall@gmail.com>2022-06-07 19:44:36 -0500
commit584213c5ffeca09b3fe24bd5e92f73fd057ac642 (patch)
tree45619273a56248d662dda598bca3076efa8a5135 /src/burn
parent648f370f7966b2738c1446601057d888bbd2c70f (diff)
downloadwix-584213c5ffeca09b3fe24bd5e92f73fd057ac642.tar.gz
wix-584213c5ffeca09b3fe24bd5e92f73fd057ac642.tar.bz2
wix-584213c5ffeca09b3fe24bd5e92f73fd057ac642.zip
Add RegReadUnexpandedString to get an unexpanded REG_EXPAND_SZ value.
Diffstat (limited to 'src/burn')
-rw-r--r--src/burn/engine/search.cpp50
-rw-r--r--src/burn/test/BurnUnitTest/TestRegistryFixture.cpp4
2 files changed, 14 insertions, 40 deletions
diff --git a/src/burn/engine/search.cpp b/src/burn/engine/search.cpp
index f521cdbd..b37dc9bd 100644
--- a/src/burn/engine/search.cpp
+++ b/src/burn/engine/search.cpp
@@ -955,15 +955,15 @@ static HRESULT RegistrySearchValue(
955 ) 955 )
956{ 956{
957 HRESULT hr = S_OK; 957 HRESULT hr = S_OK;
958 DWORD er = ERROR_SUCCESS;
959 LPWSTR sczKey = NULL; 958 LPWSTR sczKey = NULL;
960 LPWSTR sczValue = NULL; 959 LPWSTR sczValue = NULL;
961 HKEY hKey = NULL; 960 HKEY hKey = NULL;
962 DWORD dwType = 0; 961 DWORD dwType = 0;
963 DWORD cbData = 0; 962 SIZE_T cbData = 0;
964 LPBYTE pData = NULL; 963 LPBYTE pData = NULL;
965 DWORD cch = 0;
966 BURN_VARIANT value = { }; 964 BURN_VARIANT value = { };
965 DWORD dwValue = 0;
966 LONGLONG llValue = 0;
967 967
968 // format key string 968 // format key string
969 hr = VariableFormatString(pVariables, pSearch->RegistrySearch.sczKey, &sczKey, NULL); 969 hr = VariableFormatString(pVariables, pSearch->RegistrySearch.sczKey, &sczKey, NULL);
@@ -988,64 +988,38 @@ static HRESULT RegistrySearchValue(
988 ExitOnFailure(hr, "Failed to open registry key."); 988 ExitOnFailure(hr, "Failed to open registry key.");
989 989
990 // get value 990 // get value
991 er = ::RegQueryValueExW(hKey, sczValue, NULL, &dwType, NULL, &cbData); 991 hr = RegReadValue(hKey, sczValue, pSearch->RegistrySearch.fExpandEnvironment, &pData, &cbData, &dwType);
992 if (ERROR_FILE_NOT_FOUND == er) 992 if (E_FILENOTFOUND == hr)
993 { 993 {
994 // What if there is a hidden variable in sczKey or sczValue? 994 // What if there is a hidden variable in sczKey or sczValue?
995 LogStringLine(REPORT_STANDARD, "Registry value not found. Key = '%ls', Value = '%ls'", sczKey, sczValue); 995 LogStringLine(REPORT_STANDARD, "Registry value not found. Key = '%ls', Value = '%ls'", sczKey, sczValue);
996 996
997 ExitFunction1(hr = S_OK); 997 ExitFunction1(hr = S_OK);
998 } 998 }
999 ExitOnWin32Error(er, hr, "Failed to query registry key value size."); 999 ExitOnFailure(hr, "Failed to query registry key value.");
1000
1001 pData = (LPBYTE)MemAlloc(cbData + sizeof(WCHAR), TRUE); // + sizeof(WCHAR) here to ensure that we always have a null terminator for REG_SZ
1002 ExitOnNull(pData, hr, E_OUTOFMEMORY, "Failed to allocate memory registry value.");
1003
1004 er = ::RegQueryValueExW(hKey, sczValue, NULL, &dwType, pData, &cbData);
1005 ExitOnWin32Error(er, hr, "Failed to query registry key value.");
1006 1000
1007 switch (dwType) 1001 switch (dwType)
1008 { 1002 {
1009 case REG_DWORD: 1003 case REG_DWORD:
1010 if (sizeof(LONG) != cbData) 1004 if (memcpy_s(&dwValue, sizeof(DWORD), pData, cbData))
1011 { 1005 {
1012 ExitFunction1(hr = E_UNEXPECTED); 1006 ExitFunction1(hr = E_UNEXPECTED);
1013 } 1007 }
1014 hr = BVariantSetNumeric(&value, *((LONG*)pData)); 1008 hr = BVariantSetNumeric(&value, dwValue);
1015 break; 1009 break;
1016 case REG_QWORD: 1010 case REG_QWORD:
1017 if (sizeof(LONGLONG) != cbData) 1011 if (memcpy_s(&llValue, sizeof(LONGLONG), pData, cbData))
1018 { 1012 {
1019 ExitFunction1(hr = E_UNEXPECTED); 1013 ExitFunction1(hr = E_UNEXPECTED);
1020 } 1014 }
1021 hr = BVariantSetNumeric(&value, *((LONGLONG*)pData)); 1015 hr = BVariantSetNumeric(&value, llValue);
1022 break; 1016 break;
1023 case REG_EXPAND_SZ: 1017 case REG_EXPAND_SZ: __fallthrough;
1024 if (pSearch->RegistrySearch.fExpandEnvironment)
1025 {
1026 hr = StrAlloc(&value.sczValue, cbData);
1027 ExitOnFailure(hr, "Failed to allocate string buffer.");
1028 value.Type = BURN_VARIANT_TYPE_STRING;
1029
1030 cch = ::ExpandEnvironmentStringsW((LPCWSTR)pData, value.sczValue, cbData);
1031 if (cch > cbData)
1032 {
1033 hr = StrAlloc(&value.sczValue, cch);
1034 ExitOnFailure(hr, "Failed to allocate string buffer.");
1035
1036 if (cch != ::ExpandEnvironmentStringsW((LPCWSTR)pData, value.sczValue, cch))
1037 {
1038 ExitWithLastError(hr, "Failed to get expand environment string.");
1039 }
1040 }
1041 break;
1042 }
1043 __fallthrough;
1044 case REG_SZ: 1018 case REG_SZ:
1045 hr = BVariantSetString(&value, (LPCWSTR)pData, 0, FALSE); 1019 hr = BVariantSetString(&value, (LPCWSTR)pData, 0, FALSE);
1046 break; 1020 break;
1047 default: 1021 default:
1048 ExitOnFailure(hr = E_NOTIMPL, "Unsupported registry key value type. Type = '%u'", dwType); 1022 ExitWithRootFailure(hr, E_NOTIMPL, "Unsupported registry key value type. Type = '%u'", dwType);
1049 } 1023 }
1050 ExitOnFailure(hr, "Failed to read registry value."); 1024 ExitOnFailure(hr, "Failed to read registry value.");
1051 1025
diff --git a/src/burn/test/BurnUnitTest/TestRegistryFixture.cpp b/src/burn/test/BurnUnitTest/TestRegistryFixture.cpp
index 1f3d7680..89704d09 100644
--- a/src/burn/test/BurnUnitTest/TestRegistryFixture.cpp
+++ b/src/burn/test/BurnUnitTest/TestRegistryFixture.cpp
@@ -186,7 +186,7 @@ namespace WixBuildTools
186 void TestRegistryFixture::SetUp() 186 void TestRegistryFixture::SetUp()
187 { 187 {
188 // set mock API's 188 // set mock API's
189 RegFunctionOverride(TestRegistryFixture_RegCreateKeyExW, TestRegistryFixture_RegOpenKeyExW, TestRegistryFixture_RegDeleteKeyExW, NULL, NULL, NULL, NULL, NULL, NULL); 189 RegFunctionOverride(TestRegistryFixture_RegCreateKeyExW, TestRegistryFixture_RegOpenKeyExW, TestRegistryFixture_RegDeleteKeyExW, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
190 190
191 Registry::CurrentUser->CreateSubKey(TEST_REGISTRY_FIXTURE_HKCU_PATH); 191 Registry::CurrentUser->CreateSubKey(TEST_REGISTRY_FIXTURE_HKCU_PATH);
192 Registry::CurrentUser->CreateSubKey(TEST_REGISTRY_FIXTURE_HKCU32_PATH); 192 Registry::CurrentUser->CreateSubKey(TEST_REGISTRY_FIXTURE_HKCU32_PATH);
@@ -198,7 +198,7 @@ namespace WixBuildTools
198 { 198 {
199 Registry::CurrentUser->DeleteSubKeyTree(this->rootPath, false); 199 Registry::CurrentUser->DeleteSubKeyTree(this->rootPath, false);
200 200
201 RegFunctionOverride(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); 201 RegFunctionOverride(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
202 } 202 }
203 203
204 String^ TestRegistryFixture::GetDirectHkcuPath(REG_KEY_BITNESS bitness, ... array<String^>^ paths) 204 String^ TestRegistryFixture::GetDirectHkcuPath(REG_KEY_BITNESS bitness, ... array<String^>^ paths)