diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2021-07-19 16:26:53 -0500 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2021-07-19 16:57:17 -0500 |
| commit | 041cbc2ab9ca6b29841f19792c5b66fd1233dd37 (patch) | |
| tree | fd9eeadeee22ab5acaf41c1a39aadfc55d2d629e /src | |
| parent | 1bdf42c558d6923380b9f3ea409027816f972f98 (diff) | |
| download | wix-041cbc2ab9ca6b29841f19792c5b66fd1233dd37.tar.gz wix-041cbc2ab9ca6b29841f19792c5b66fd1233dd37.tar.bz2 wix-041cbc2ab9ca6b29841f19792c5b66fd1233dd37.zip | |
Fix more 32-bit assumptions.
Use strutil to return value in BundleGetBundleInfo.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libs/dutil/WixToolset.DUtil/butil.cpp | 40 | ||||
| -rw-r--r-- | src/libs/dutil/WixToolset.DUtil/inc/butil.h | 12 |
2 files changed, 12 insertions, 40 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( | |||
| 61 | DAPI_(HRESULT) BundleGetBundleInfo( | 61 | DAPI_(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 | |||
| 130 | LExit: | 107 | LExit: |
| 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; |
diff --git a/src/libs/dutil/WixToolset.DUtil/inc/butil.h b/src/libs/dutil/WixToolset.DUtil/inc/butil.h index 721d9ad6..989d4237 100644 --- a/src/libs/dutil/WixToolset.DUtil/inc/butil.h +++ b/src/libs/dutil/WixToolset.DUtil/inc/butil.h | |||
| @@ -14,7 +14,8 @@ typedef enum _BUNDLE_INSTALL_CONTEXT | |||
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | /******************************************************************** | 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 | ||
| 18 | 19 | ||
| 19 | RETURNS: | 20 | RETURNS: |
| 20 | E_INVALIDARG | 21 | E_INVALIDARG |
| @@ -23,18 +24,15 @@ RETURNS: | |||
| 23 | The bundle is not installed | 24 | The bundle is not installed |
| 24 | HRESULT_FROM_WIN32(ERROR_UNKNOWN_PROPERTY) | 25 | HRESULT_FROM_WIN32(ERROR_UNKNOWN_PROPERTY) |
| 25 | The property is unrecognized | 26 | The property is unrecognized |
| 26 | HRESULT_FROM_WIN32(ERROR_MORE_DATA) | ||
| 27 | A buffer is too small to hold the requested data. | ||
| 28 | E_NOTIMPL: | 27 | E_NOTIMPL: |
| 29 | Tried to read a bundle attribute for a type which has not been implemented | 28 | Tried to read a bundle attribute for a type which has not been implemented |
| 30 | 29 | ||
| 31 | All other returns are unexpected returns from other dutil methods. | 30 | All other returns are unexpected returns from other dutil methods. |
| 32 | ********************************************************************/ | 31 | ********************************************************************/ |
| 33 | HRESULT DAPI BundleGetBundleInfo( | 32 | HRESULT DAPI BundleGetBundleInfo( |
| 34 | __in_z LPCWSTR szBundleId, // Bundle code | 33 | __in_z LPCWSTR szBundleId, |
| 35 | __in_z LPCWSTR szAttribute, // attribute name | 34 | __in_z LPCWSTR szAttribute, |
| 36 | __out_ecount_opt(*pcchValueBuf) LPWSTR lpValueBuf, // returned value, NULL if not desired | 35 | __deref_out_z LPWSTR* psczValue |
| 37 | __inout_opt LPDWORD pcchValueBuf // in/out buffer character count | ||
| 38 | ); | 36 | ); |
| 39 | 37 | ||
| 40 | /******************************************************************** | 38 | /******************************************************************** |
