aboutsummaryrefslogtreecommitdiff
path: root/src/libs/dutil/WixToolset.DUtil/butil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil/butil.cpp')
-rw-r--r--src/libs/dutil/WixToolset.DUtil/butil.cpp40
1 files changed, 7 insertions, 33 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/butil.cpp b/src/libs/dutil/WixToolset.DUtil/butil.cpp
index ca73f0c3..5e980699 100644
--- a/src/libs/dutil/WixToolset.DUtil/butil.cpp
+++ b/src/libs/dutil/WixToolset.DUtil/butil.cpp
@@ -61,21 +61,16 @@ static HRESULT OpenBundleKey(
61DAPI_(HRESULT) BundleGetBundleInfo( 61DAPI_(HRESULT) BundleGetBundleInfo(
62 __in_z LPCWSTR wzBundleId, 62 __in_z LPCWSTR wzBundleId,
63 __in_z LPCWSTR wzAttribute, 63 __in_z LPCWSTR wzAttribute,
64 __out_ecount_opt(*pcchValueBuf) LPWSTR lpValueBuf, 64 __deref_out_z LPWSTR* psczValue
65 __inout_opt LPDWORD pcchValueBuf
66 ) 65 )
67{ 66{
68 Assert(wzBundleId && wzAttribute);
69
70 HRESULT hr = S_OK; 67 HRESULT hr = S_OK;
71 LPWSTR sczValue = NULL;
72 HKEY hkBundle = NULL; 68 HKEY hkBundle = NULL;
73 INTERNAL_BUNDLE_STATUS status = INTERNAL_BUNDLE_STATUS_SUCCESS; 69 INTERNAL_BUNDLE_STATUS status = INTERNAL_BUNDLE_STATUS_SUCCESS;
74 DWORD cchSource = 0;
75 DWORD dwType = 0; 70 DWORD dwType = 0;
76 DWORD dwValue = 0; 71 DWORD dwValue = 0;
77 72
78 if ((lpValueBuf && !pcchValueBuf) || !wzBundleId || !wzAttribute) 73 if (!wzBundleId || !wzAttribute || !psczValue)
79 { 74 {
80 ButilExitWithRootFailure(hr, E_INVALIDARG, "An invalid parameter was passed to the function."); 75 ButilExitWithRootFailure(hr, E_INVALIDARG, "An invalid parameter was passed to the function.");
81 } 76 }
@@ -95,41 +90,22 @@ DAPI_(HRESULT) BundleGetBundleInfo(
95 switch (dwType) 90 switch (dwType)
96 { 91 {
97 case REG_SZ: 92 case REG_SZ:
98 hr = RegReadString(hkBundle, wzAttribute, &sczValue); 93 hr = RegReadString(hkBundle, wzAttribute, psczValue);
99 ButilExitOnFailure(hr, "Failed to read string property."); 94 ButilExitOnFailure(hr, "Failed to read string property.");
100 break; 95 break;
101 case REG_DWORD: 96 case REG_DWORD:
102 hr = RegReadNumber(hkBundle, wzAttribute, &dwValue); 97 hr = RegReadNumber(hkBundle, wzAttribute, &dwValue);
103 ButilExitOnFailure(hr, "Failed to read dword property."); 98 ButilExitOnFailure(hr, "Failed to read dword property.");
104 99
105 hr = StrAllocFormatted(&sczValue, L"%d", dwValue); 100 hr = StrAllocFormatted(psczValue, L"%d", dwValue);
106 ButilExitOnFailure(hr, "Failed to format dword property as string."); 101 ButilExitOnFailure(hr, "Failed to format dword property as string.");
107 break; 102 break;
108 default: 103 default:
109 ButilExitWithRootFailure(hr, E_NOTIMPL, "Reading bundle info of type 0x%x not implemented.", dwType); 104 ButilExitWithRootFailure(hr, E_NOTIMPL, "Reading bundle info of type 0x%x not implemented.", dwType);
110 } 105 }
111 106
112 hr = ::StringCchLengthW(sczValue, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchSource));
113 ButilExitOnRootFailure(hr, "Failed to calculate length of string.");
114
115 if (lpValueBuf)
116 {
117 // cchSource is the length of the string not including the terminating null character
118 if (*pcchValueBuf <= cchSource)
119 {
120 *pcchValueBuf = ++cchSource;
121 ExitFunction1(hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA));
122 }
123
124 hr = ::StringCchCatNExW(lpValueBuf, *pcchValueBuf, sczValue, cchSource, NULL, NULL, STRSAFE_FILL_BEHIND_NULL);
125 ButilExitOnRootFailure(hr, "Failed to copy the property value to the output buffer.");
126
127 *pcchValueBuf = cchSource++;
128 }
129
130LExit: 107LExit:
131 ReleaseRegKey(hkBundle); 108 ReleaseRegKey(hkBundle);
132 ReleaseStr(sczValue);
133 109
134 return hr; 110 return hr;
135} 111}
@@ -147,7 +123,7 @@ DAPI_(HRESULT) BundleEnumRelatedBundle(
147 HKEY hkUninstall = NULL; 123 HKEY hkUninstall = NULL;
148 HKEY hkBundle = NULL; 124 HKEY hkBundle = NULL;
149 LPWSTR sczUninstallSubKey = NULL; 125 LPWSTR sczUninstallSubKey = NULL;
150 DWORD cchUninstallSubKey = 0; 126 size_t cchUninstallSubKey = 0;
151 LPWSTR sczUninstallSubKeyPath = NULL; 127 LPWSTR sczUninstallSubKeyPath = NULL;
152 LPWSTR sczValue = NULL; 128 LPWSTR sczValue = NULL;
153 DWORD dwType = 0; 129 DWORD dwType = 0;
@@ -231,8 +207,8 @@ DAPI_(HRESULT) BundleEnumRelatedBundle(
231 { 207 {
232 if (lpBundleIdBuf) 208 if (lpBundleIdBuf)
233 { 209 {
234 hr = ::StringCchLengthW(sczUninstallSubKey, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchUninstallSubKey)); 210 hr = ::StringCchLengthW(sczUninstallSubKey, STRSAFE_MAX_CCH, &cchUninstallSubKey);
235 ButilExitOnRootFailure(hr, "Failed to calculate length of string"); 211 ButilExitOnRootFailure(hr, "Failed to calculate length of string.");
236 212
237 hr = ::StringCchCopyNExW(lpBundleIdBuf, MAX_GUID_CHARS + 1, sczUninstallSubKey, cchUninstallSubKey, NULL, NULL, STRSAFE_FILL_BEHIND_NULL); 213 hr = ::StringCchCopyNExW(lpBundleIdBuf, MAX_GUID_CHARS + 1, sczUninstallSubKey, cchUninstallSubKey, NULL, NULL, STRSAFE_FILL_BEHIND_NULL);
238 ButilExitOnRootFailure(hr, "Failed to copy the property value to the output buffer."); 214 ButilExitOnRootFailure(hr, "Failed to copy the property value to the output buffer.");
@@ -265,8 +241,6 @@ DAPI_(HRESULT) BundleGetBundleVariable(
265 __deref_out_z LPWSTR* psczValue 241 __deref_out_z LPWSTR* psczValue
266 ) 242 )
267{ 243{
268 Assert(wzBundleId && wzVariable);
269
270 HRESULT hr = S_OK; 244 HRESULT hr = S_OK;
271 HKEY hkBundle = NULL; 245 HKEY hkBundle = NULL;
272 INTERNAL_BUNDLE_STATUS status = INTERNAL_BUNDLE_STATUS_SUCCESS; 246 INTERNAL_BUNDLE_STATUS status = INTERNAL_BUNDLE_STATUS_SUCCESS;