From 041cbc2ab9ca6b29841f19792c5b66fd1233dd37 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Mon, 19 Jul 2021 16:26:53 -0500 Subject: Fix more 32-bit assumptions. Use strutil to return value in BundleGetBundleInfo. --- src/libs/dutil/WixToolset.DUtil/butil.cpp | 40 +++++------------------------ 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( DAPI_(HRESULT) BundleGetBundleInfo( __in_z LPCWSTR wzBundleId, __in_z LPCWSTR wzAttribute, - __out_ecount_opt(*pcchValueBuf) LPWSTR lpValueBuf, - __inout_opt LPDWORD pcchValueBuf + __deref_out_z LPWSTR* psczValue ) { - Assert(wzBundleId && wzAttribute); - HRESULT hr = S_OK; - LPWSTR sczValue = NULL; HKEY hkBundle = NULL; INTERNAL_BUNDLE_STATUS status = INTERNAL_BUNDLE_STATUS_SUCCESS; - DWORD cchSource = 0; DWORD dwType = 0; DWORD dwValue = 0; - if ((lpValueBuf && !pcchValueBuf) || !wzBundleId || !wzAttribute) + if (!wzBundleId || !wzAttribute || !psczValue) { ButilExitWithRootFailure(hr, E_INVALIDARG, "An invalid parameter was passed to the function."); } @@ -95,41 +90,22 @@ DAPI_(HRESULT) BundleGetBundleInfo( switch (dwType) { case REG_SZ: - hr = RegReadString(hkBundle, wzAttribute, &sczValue); + hr = RegReadString(hkBundle, wzAttribute, psczValue); ButilExitOnFailure(hr, "Failed to read string property."); break; case REG_DWORD: hr = RegReadNumber(hkBundle, wzAttribute, &dwValue); ButilExitOnFailure(hr, "Failed to read dword property."); - hr = StrAllocFormatted(&sczValue, L"%d", dwValue); + hr = StrAllocFormatted(psczValue, L"%d", dwValue); ButilExitOnFailure(hr, "Failed to format dword property as string."); break; default: ButilExitWithRootFailure(hr, E_NOTIMPL, "Reading bundle info of type 0x%x not implemented.", dwType); } - hr = ::StringCchLengthW(sczValue, STRSAFE_MAX_CCH, reinterpret_cast(&cchSource)); - ButilExitOnRootFailure(hr, "Failed to calculate length of string."); - - if (lpValueBuf) - { - // cchSource is the length of the string not including the terminating null character - if (*pcchValueBuf <= cchSource) - { - *pcchValueBuf = ++cchSource; - ExitFunction1(hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA)); - } - - hr = ::StringCchCatNExW(lpValueBuf, *pcchValueBuf, sczValue, cchSource, NULL, NULL, STRSAFE_FILL_BEHIND_NULL); - ButilExitOnRootFailure(hr, "Failed to copy the property value to the output buffer."); - - *pcchValueBuf = cchSource++; - } - LExit: ReleaseRegKey(hkBundle); - ReleaseStr(sczValue); return hr; } @@ -147,7 +123,7 @@ DAPI_(HRESULT) BundleEnumRelatedBundle( HKEY hkUninstall = NULL; HKEY hkBundle = NULL; LPWSTR sczUninstallSubKey = NULL; - DWORD cchUninstallSubKey = 0; + size_t cchUninstallSubKey = 0; LPWSTR sczUninstallSubKeyPath = NULL; LPWSTR sczValue = NULL; DWORD dwType = 0; @@ -231,8 +207,8 @@ DAPI_(HRESULT) BundleEnumRelatedBundle( { if (lpBundleIdBuf) { - hr = ::StringCchLengthW(sczUninstallSubKey, STRSAFE_MAX_CCH, reinterpret_cast(&cchUninstallSubKey)); - ButilExitOnRootFailure(hr, "Failed to calculate length of string"); + hr = ::StringCchLengthW(sczUninstallSubKey, STRSAFE_MAX_CCH, &cchUninstallSubKey); + ButilExitOnRootFailure(hr, "Failed to calculate length of string."); hr = ::StringCchCopyNExW(lpBundleIdBuf, MAX_GUID_CHARS + 1, sczUninstallSubKey, cchUninstallSubKey, NULL, NULL, STRSAFE_FILL_BEHIND_NULL); ButilExitOnRootFailure(hr, "Failed to copy the property value to the output buffer."); @@ -265,8 +241,6 @@ DAPI_(HRESULT) BundleGetBundleVariable( __deref_out_z LPWSTR* psczValue ) { - Assert(wzBundleId && wzVariable); - HRESULT hr = S_OK; HKEY hkBundle = NULL; 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 /******************************************************************** -BundleGetBundleInfo - Queries the bundle installation metadata for a given property +BundleGetBundleInfo - Queries the bundle installation metadata for a given property, + the caller is expected to free the memory returned vis psczValue RETURNS: E_INVALIDARG @@ -23,18 +24,15 @@ RETURNS: The bundle is not installed HRESULT_FROM_WIN32(ERROR_UNKNOWN_PROPERTY) The property is unrecognized - HRESULT_FROM_WIN32(ERROR_MORE_DATA) - A buffer is too small to hold the requested data. E_NOTIMPL: Tried to read a bundle attribute for a type which has not been implemented All other returns are unexpected returns from other dutil methods. ********************************************************************/ HRESULT DAPI BundleGetBundleInfo( - __in_z LPCWSTR szBundleId, // Bundle code - __in_z LPCWSTR szAttribute, // attribute name - __out_ecount_opt(*pcchValueBuf) LPWSTR lpValueBuf, // returned value, NULL if not desired - __inout_opt LPDWORD pcchValueBuf // in/out buffer character count + __in_z LPCWSTR szBundleId, + __in_z LPCWSTR szAttribute, + __deref_out_z LPWSTR* psczValue ); /******************************************************************** -- cgit v1.2.3-55-g6feb