@joebigelow / wix-1 / commits / 041cbc2a

Fix more 32-bit assumptions.

Use strutil to return value in BundleGetBundleInfo.

Sean Hall committed Jul 19, 2021 at 16:26 UTC 041cbc2ab9ca6b29841f19792c5b66fd1233dd37
2 files changed +12 -40
src/libs/dutil/WixToolset.DUtil/butil.cpp
+7 -33
@@ -61,21 +61,16 @@ static HRESULT OpenBundleKey(
61 DAPI_(HRESULT) BundleGetBundleInfo(
62 __in_z LPCWSTR wzBundleId,
63 __in_z LPCWSTR wzAttribute,
64 - __out_ecount_opt(*pcchValueBuf) LPWSTR lpValueBuf,
65 - __inout_opt LPDWORD pcchValueBuf
64 + __deref_out_z LPWSTR* psczValue
65 )
66 {
68 - Assert(wzBundleId && wzAttribute);
69 -
67 HRESULT hr = S_OK;
71 - LPWSTR sczValue = NULL;
68 HKEY hkBundle = NULL;
69 INTERNAL_BUNDLE_STATUS status = INTERNAL_BUNDLE_STATUS_SUCCESS;
74 - DWORD cchSource = 0;
70 DWORD dwType = 0;
71 DWORD dwValue = 0;
72
78 - if ((lpValueBuf && !pcchValueBuf) || !wzBundleId || !wzAttribute)
73 + if (!wzBundleId || !wzAttribute || !psczValue)
74 {
75 ButilExitWithRootFailure(hr, E_INVALIDARG, "An invalid parameter was passed to the function.");
76 }
@@ -95,41 +90,22 @@ DAPI_(HRESULT) BundleGetBundleInfo(
90 switch (dwType)
91 {
92 case REG_SZ:
98 - hr = RegReadString(hkBundle, wzAttribute, &sczValue);
93 + hr = RegReadString(hkBundle, wzAttribute, psczValue);
94 ButilExitOnFailure(hr, "Failed to read string property.");
95 break;
96 case REG_DWORD:
97 hr = RegReadNumber(hkBundle, wzAttribute, &dwValue);
98 ButilExitOnFailure(hr, "Failed to read dword property.");
99
105 - hr = StrAllocFormatted(&sczValue, L"%d", dwValue);
100 + hr = StrAllocFormatted(psczValue, L"%d", dwValue);
101 ButilExitOnFailure(hr, "Failed to format dword property as string.");
102 break;
103 default:
104 ButilExitWithRootFailure(hr, E_NOTIMPL, "Reading bundle info of type 0x%x not implemented.", dwType);
105 }
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 -
107 LExit:
108 ReleaseRegKey(hkBundle);
132 - ReleaseStr(sczValue);
109
110 return hr;
111 }
@@ -147,7 +123,7 @@ DAPI_(HRESULT) BundleEnumRelatedBundle(
123 HKEY hkUninstall = NULL;
124 HKEY hkBundle = NULL;
125 LPWSTR sczUninstallSubKey = NULL;
150 - DWORD cchUninstallSubKey = 0;
126 + size_t cchUninstallSubKey = 0;
127 LPWSTR sczUninstallSubKeyPath = NULL;
128 LPWSTR sczValue = NULL;
129 DWORD dwType = 0;
@@ -231,8 +207,8 @@ DAPI_(HRESULT) BundleEnumRelatedBundle(
207 {
208 if (lpBundleIdBuf)
209 {
234 - hr = ::StringCchLengthW(sczUninstallSubKey, STRSAFE_MAX_CCH, reinterpret_cast<UINT_PTR*>(&cchUninstallSubKey));
235 - ButilExitOnRootFailure(hr, "Failed to calculate length of string");
210 + hr = ::StringCchLengthW(sczUninstallSubKey, STRSAFE_MAX_CCH, &cchUninstallSubKey);
211 + ButilExitOnRootFailure(hr, "Failed to calculate length of string.");
212
213 hr = ::StringCchCopyNExW(lpBundleIdBuf, MAX_GUID_CHARS + 1, sczUninstallSubKey, cchUninstallSubKey, NULL, NULL, STRSAFE_FILL_BEHIND_NULL);
214 ButilExitOnRootFailure(hr, "Failed to copy the property value to the output buffer.");
@@ -265,8 +241,6 @@ DAPI_(HRESULT) BundleGetBundleVariable(
241 __deref_out_z LPWSTR* psczValue
242 )
243 {
268 - Assert(wzBundleId && wzVariable);
269 -
244 HRESULT hr = S_OK;
245 HKEY hkBundle = NULL;
246 INTERNAL_BUNDLE_STATUS status = INTERNAL_BUNDLE_STATUS_SUCCESS;
src/libs/dutil/WixToolset.DUtil/inc/butil.h
+5 -7
@@ -14,7 +14,8 @@ typedef enum _BUNDLE_INSTALL_CONTEXT
14
15
16 /********************************************************************
17 -BundleGetBundleInfo - Queries the bundle installation metadata for a given property
17 +BundleGetBundleInfo - Queries the bundle installation metadata for a given property,
18 + the caller is expected to free the memory returned vis psczValue
19
20 RETURNS:
21 E_INVALIDARG
@@ -23,18 +24,15 @@ RETURNS:
24 The bundle is not installed
25 HRESULT_FROM_WIN32(ERROR_UNKNOWN_PROPERTY)
26 The property is unrecognized
26 - HRESULT_FROM_WIN32(ERROR_MORE_DATA)
27 - A buffer is too small to hold the requested data.
27 E_NOTIMPL:
28 Tried to read a bundle attribute for a type which has not been implemented
29
30 All other returns are unexpected returns from other dutil methods.
31 ********************************************************************/
32 HRESULT DAPI BundleGetBundleInfo(
34 - __in_z LPCWSTR szBundleId, // Bundle code
35 - __in_z LPCWSTR szAttribute, // attribute name
36 - __out_ecount_opt(*pcchValueBuf) LPWSTR lpValueBuf, // returned value, NULL if not desired
37 - __inout_opt LPDWORD pcchValueBuf // in/out buffer character count
33 + __in_z LPCWSTR szBundleId,
34 + __in_z LPCWSTR szAttribute,
35 + __deref_out_z LPWSTR* psczValue
36 );
37
38 /********************************************************************