diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2021-04-28 18:12:36 -0500 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2021-04-29 14:02:02 -0500 |
| commit | 46897fefd6aef4168f35c1f366c833d715c3bdaa (patch) | |
| tree | 852312345c583c35315f283af76f85d6f0b7674c /src | |
| parent | cacae742b21e42c6c7a1cd7c9ddd102264ac0782 (diff) | |
| download | wix-46897fefd6aef4168f35c1f366c833d715c3bdaa.tar.gz wix-46897fefd6aef4168f35c1f366c833d715c3bdaa.tar.bz2 wix-46897fefd6aef4168f35c1f366c833d715c3bdaa.zip | |
Clean up more 32-bit assumptions.
Diffstat (limited to 'src')
| -rw-r--r-- | src/wcautil/packages.config | 2 | ||||
| -rw-r--r-- | src/wcautil/wcalog.cpp | 6 | ||||
| -rw-r--r-- | src/wcautil/wcascript.cpp | 32 | ||||
| -rw-r--r-- | src/wcautil/wcautil.vcxproj | 4 | ||||
| -rw-r--r-- | src/wcautil/wcawrap.cpp | 89 | ||||
| -rw-r--r-- | src/wcautil/wcawrapquery.cpp | 4 |
6 files changed, 72 insertions, 65 deletions
diff --git a/src/wcautil/packages.config b/src/wcautil/packages.config index aee0138c..aa8b4077 100644 --- a/src/wcautil/packages.config +++ b/src/wcautil/packages.config | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
| 2 | <packages> | 2 | <packages> |
| 3 | <package id="Nerdbank.GitVersioning" version="2.1.65" developmentDependency="true" targetFramework="net40" /> | 3 | <package id="Nerdbank.GitVersioning" version="2.1.65" developmentDependency="true" targetFramework="net40" /> |
| 4 | <package id="WixToolset.DUtil" version="4.0.62" targetFramework="native" /> | 4 | <package id="WixToolset.DUtil" version="4.0.72" targetFramework="native" /> |
| 5 | </packages> \ No newline at end of file | 5 | </packages> \ No newline at end of file |
diff --git a/src/wcautil/wcalog.cpp b/src/wcautil/wcalog.cpp index faa7f8fd..cc7d1438 100644 --- a/src/wcautil/wcalog.cpp +++ b/src/wcautil/wcalog.cpp | |||
| @@ -54,10 +54,10 @@ BOOL WIXAPI IsVerboseLogging() | |||
| 54 | // if the property wasn't set, check the MsiLogging property (MSI 4.0+) | 54 | // if the property wasn't set, check the MsiLogging property (MSI 4.0+) |
| 55 | HRESULT hr = WcaGetProperty(L"MsiLogging", &pwzMsiLogging); | 55 | HRESULT hr = WcaGetProperty(L"MsiLogging", &pwzMsiLogging); |
| 56 | ExitOnFailure(hr, "failed to get MsiLogging property"); | 56 | ExitOnFailure(hr, "failed to get MsiLogging property"); |
| 57 | int cchMsiLogging = lstrlenW(pwzMsiLogging); | 57 | |
| 58 | if (0 < cchMsiLogging) | 58 | if (pwzMsiLogging) |
| 59 | { | 59 | { |
| 60 | for (int i = 0; i < cchMsiLogging; i++) | 60 | for (int i = 0; pwzMsiLogging[i]; i++) |
| 61 | { | 61 | { |
| 62 | if (L'v' == pwzMsiLogging[i] || L'V' == pwzMsiLogging[i]) | 62 | if (L'v' == pwzMsiLogging[i] || L'V' == pwzMsiLogging[i]) |
| 63 | { | 63 | { |
diff --git a/src/wcautil/wcascript.cpp b/src/wcautil/wcascript.cpp index b6629850..a7e98491 100644 --- a/src/wcautil/wcascript.cpp +++ b/src/wcautil/wcascript.cpp | |||
| @@ -247,9 +247,8 @@ extern "C" HRESULT WIXAPI WcaCaScriptWriteString( | |||
| 247 | { | 247 | { |
| 248 | HRESULT hr = S_OK; | 248 | HRESULT hr = S_OK; |
| 249 | DWORD cbFile = 0; | 249 | DWORD cbFile = 0; |
| 250 | DWORD cbWrite = 0; | ||
| 251 | DWORD cbTotalWritten = 0; | ||
| 252 | WCHAR delim[] = { MAGIC_MULTISZ_DELIM }; // magic char followed by NULL terminator | 250 | WCHAR delim[] = { MAGIC_MULTISZ_DELIM }; // magic char followed by NULL terminator |
| 251 | SIZE_T cch = 0; | ||
| 253 | 252 | ||
| 254 | cbFile = ::SetFilePointer(hScript->hScriptFile, 0, NULL, FILE_END); | 253 | cbFile = ::SetFilePointer(hScript->hScriptFile, 0, NULL, FILE_END); |
| 255 | if (INVALID_SET_FILE_POINTER == cbFile) | 254 | if (INVALID_SET_FILE_POINTER == cbFile) |
| @@ -261,32 +260,15 @@ extern "C" HRESULT WIXAPI WcaCaScriptWriteString( | |||
| 261 | // before adding our new data on the end of the file. | 260 | // before adding our new data on the end of the file. |
| 262 | if (0 < cbFile) | 261 | if (0 < cbFile) |
| 263 | { | 262 | { |
| 264 | cbWrite = sizeof(delim); | 263 | hr = FileWriteHandle(hScript->hScriptFile, reinterpret_cast<LPCBYTE>(delim), sizeof(delim)); |
| 265 | cbTotalWritten = 0; | 264 | ExitOnFailure(hr, "Failed to write data to ca script."); |
| 266 | while (cbTotalWritten < cbWrite) | ||
| 267 | { | ||
| 268 | DWORD cbWritten = 0; | ||
| 269 | if (!::WriteFile(hScript->hScriptFile, reinterpret_cast<BYTE*>(delim) + cbTotalWritten, cbWrite - cbTotalWritten, &cbWritten, NULL)) | ||
| 270 | { | ||
| 271 | ExitWithLastError(hr, "Failed to write data to ca script."); | ||
| 272 | } | ||
| 273 | |||
| 274 | cbTotalWritten += cbWritten; | ||
| 275 | } | ||
| 276 | } | 265 | } |
| 277 | 266 | ||
| 278 | cbWrite = lstrlenW(wzValue) * sizeof(WCHAR); | 267 | hr = ::StringCchLengthW(wzValue, STRSAFE_MAX_CCH, reinterpret_cast<size_t*>(&cch)); |
| 279 | cbTotalWritten = 0; | 268 | ExitOnRootFailure(hr, "Failed to get length of ca script string."); |
| 280 | while (cbTotalWritten < cbWrite) | ||
| 281 | { | ||
| 282 | DWORD cbWritten = 0; | ||
| 283 | if (!::WriteFile(hScript->hScriptFile, reinterpret_cast<const BYTE*>(wzValue) + cbTotalWritten, cbWrite - cbTotalWritten, &cbWritten, NULL)) | ||
| 284 | { | ||
| 285 | ExitWithLastError(hr, "Failed to write data to ca script."); | ||
| 286 | } | ||
| 287 | 269 | ||
| 288 | cbTotalWritten += cbWritten; | 270 | hr = FileWriteHandle(hScript->hScriptFile, reinterpret_cast<LPCBYTE>(wzValue), static_cast<DWORD>(cch) * sizeof(WCHAR)); |
| 289 | } | 271 | ExitOnFailure(hr, "Failed to write data to ca script."); |
| 290 | 272 | ||
| 291 | LExit: | 273 | LExit: |
| 292 | return hr; | 274 | return hr; |
diff --git a/src/wcautil/wcautil.vcxproj b/src/wcautil/wcautil.vcxproj index c5b60b4a..6876bd5b 100644 --- a/src/wcautil/wcautil.vcxproj +++ b/src/wcautil/wcautil.vcxproj | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
| 2 | <!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. --> | 2 | <!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. --> |
| 3 | <Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | 3 | <Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
| 4 | <Import Project="..\..\packages\WixToolset.DUtil.4.0.62\build\WixToolset.DUtil.props" Condition="Exists('..\..\packages\WixToolset.DUtil.4.0.62\build\WixToolset.DUtil.props')" /> | 4 | <Import Project="..\..\packages\WixToolset.DUtil.4.0.72\build\WixToolset.DUtil.props" Condition="Exists('..\..\packages\WixToolset.DUtil.4.0.72\build\WixToolset.DUtil.props')" /> |
| 5 | <ItemGroup Label="ProjectConfigurations"> | 5 | <ItemGroup Label="ProjectConfigurations"> |
| 6 | <ProjectConfiguration Include="Debug|ARM64"> | 6 | <ProjectConfiguration Include="Debug|ARM64"> |
| 7 | <Configuration>Debug</Configuration> | 7 | <Configuration>Debug</Configuration> |
| @@ -89,6 +89,6 @@ | |||
| 89 | <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> | 89 | <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> |
| 90 | </PropertyGroup> | 90 | </PropertyGroup> |
| 91 | <Error Condition="!Exists('..\..\packages\Nerdbank.GitVersioning.2.1.65\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Nerdbank.GitVersioning.2.1.65\build\Nerdbank.GitVersioning.targets'))" /> | 91 | <Error Condition="!Exists('..\..\packages\Nerdbank.GitVersioning.2.1.65\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Nerdbank.GitVersioning.2.1.65\build\Nerdbank.GitVersioning.targets'))" /> |
| 92 | <Error Condition="!Exists('..\..\packages\WixToolset.DUtil.4.0.62\build\WixToolset.DUtil.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\WixToolset.DUtil.4.0.62\build\WixToolset.DUtil.props'))" /> | 92 | <Error Condition="!Exists('..\..\packages\WixToolset.DUtil.4.0.72\build\WixToolset.DUtil.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\WixToolset.DUtil.4.0.72\build\WixToolset.DUtil.props'))" /> |
| 93 | </Target> | 93 | </Target> |
| 94 | </Project> \ No newline at end of file | 94 | </Project> \ No newline at end of file |
diff --git a/src/wcautil/wcawrap.cpp b/src/wcautil/wcawrap.cpp index 7c210069..2b68f36f 100644 --- a/src/wcautil/wcawrap.cpp +++ b/src/wcautil/wcawrap.cpp | |||
| @@ -467,12 +467,13 @@ extern "C" HRESULT WIXAPI WcaGetProperty( | |||
| 467 | 467 | ||
| 468 | HRESULT hr = S_OK; | 468 | HRESULT hr = S_OK; |
| 469 | UINT er = ERROR_SUCCESS; | 469 | UINT er = ERROR_SUCCESS; |
| 470 | DWORD_PTR cch = 0; | 470 | DWORD cch = 0; |
| 471 | SIZE_T cchMax = 0; | ||
| 471 | 472 | ||
| 472 | if (!*ppwzData) | 473 | if (!*ppwzData) |
| 473 | { | 474 | { |
| 474 | WCHAR szEmpty[1] = L""; | 475 | WCHAR szEmpty[1] = L""; |
| 475 | er = ::MsiGetPropertyW(WcaGetInstallHandle(), wzProperty, szEmpty, (DWORD *)&cch); | 476 | er = ::MsiGetPropertyW(WcaGetInstallHandle(), wzProperty, szEmpty, &cch); |
| 476 | if (ERROR_MORE_DATA == er || ERROR_SUCCESS == er) | 477 | if (ERROR_MORE_DATA == er || ERROR_SUCCESS == er) |
| 477 | { | 478 | { |
| 478 | hr = StrAlloc(ppwzData, ++cch); | 479 | hr = StrAlloc(ppwzData, ++cch); |
| @@ -481,22 +482,24 @@ extern "C" HRESULT WIXAPI WcaGetProperty( | |||
| 481 | { | 482 | { |
| 482 | hr = HRESULT_FROM_WIN32(er); | 483 | hr = HRESULT_FROM_WIN32(er); |
| 483 | } | 484 | } |
| 484 | ExitOnFailure(hr, "Failed to allocate string for Property '%ls'", wzProperty); | 485 | ExitOnRootFailure(hr, "Failed to allocate string for Property '%ls'", wzProperty); |
| 485 | } | 486 | } |
| 486 | else | 487 | else |
| 487 | { | 488 | { |
| 488 | hr = StrMaxLength(*ppwzData, &cch); | 489 | hr = StrMaxLength(*ppwzData, &cchMax); |
| 489 | ExitOnFailure(hr, "Failed to get previous size of property data string."); | 490 | ExitOnFailure(hr, "Failed to get previous size of property data string."); |
| 491 | |||
| 492 | cch = (DWORD)min(MAXDWORD, cchMax); | ||
| 490 | } | 493 | } |
| 491 | 494 | ||
| 492 | er = ::MsiGetPropertyW(WcaGetInstallHandle(), wzProperty, *ppwzData, (DWORD *)&cch); | 495 | er = ::MsiGetPropertyW(WcaGetInstallHandle(), wzProperty, *ppwzData, &cch); |
| 493 | if (ERROR_MORE_DATA == er) | 496 | if (ERROR_MORE_DATA == er) |
| 494 | { | 497 | { |
| 495 | Assert(*ppwzData); | 498 | Assert(*ppwzData); |
| 496 | hr = StrAlloc(ppwzData, ++cch); | 499 | hr = StrAlloc(ppwzData, ++cch); |
| 497 | ExitOnFailure(hr, "Failed to allocate string for Property '%ls'", wzProperty); | 500 | ExitOnFailure(hr, "Failed to allocate string for Property '%ls'", wzProperty); |
| 498 | 501 | ||
| 499 | er = ::MsiGetPropertyW(WcaGetInstallHandle(), wzProperty, *ppwzData, (DWORD *)&cch); | 502 | er = ::MsiGetPropertyW(WcaGetInstallHandle(), wzProperty, *ppwzData, &cch); |
| 500 | } | 503 | } |
| 501 | ExitOnWin32Error(er, hr, "Failed to get data for property '%ls'", wzProperty); | 504 | ExitOnWin32Error(er, hr, "Failed to get data for property '%ls'", wzProperty); |
| 502 | 505 | ||
| @@ -554,7 +557,8 @@ extern "C" HRESULT WIXAPI WcaGetFormattedString( | |||
| 554 | HRESULT hr = S_OK; | 557 | HRESULT hr = S_OK; |
| 555 | UINT er = ERROR_SUCCESS; | 558 | UINT er = ERROR_SUCCESS; |
| 556 | PMSIHANDLE hRecord = ::MsiCreateRecord(1); | 559 | PMSIHANDLE hRecord = ::MsiCreateRecord(1); |
| 557 | DWORD_PTR cch = 0; | 560 | DWORD cch = 0; |
| 561 | SIZE_T cchMax = 0; | ||
| 558 | 562 | ||
| 559 | er = ::MsiRecordSetStringW(hRecord, 0, wzString); | 563 | er = ::MsiRecordSetStringW(hRecord, 0, wzString); |
| 560 | ExitOnWin32Error(er, hr, "Failed to set record field 0 with '%ls'", wzString); | 564 | ExitOnWin32Error(er, hr, "Failed to set record field 0 with '%ls'", wzString); |
| @@ -562,7 +566,7 @@ extern "C" HRESULT WIXAPI WcaGetFormattedString( | |||
| 562 | if (!*ppwzData) | 566 | if (!*ppwzData) |
| 563 | { | 567 | { |
| 564 | WCHAR szEmpty[1] = L""; | 568 | WCHAR szEmpty[1] = L""; |
| 565 | er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecord, szEmpty, (DWORD *)&cch); | 569 | er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecord, szEmpty, &cch); |
| 566 | if (ERROR_MORE_DATA == er || ERROR_SUCCESS == er) | 570 | if (ERROR_MORE_DATA == er || ERROR_SUCCESS == er) |
| 567 | { | 571 | { |
| 568 | hr = StrAlloc(ppwzData, ++cch); | 572 | hr = StrAlloc(ppwzData, ++cch); |
| @@ -575,17 +579,19 @@ extern "C" HRESULT WIXAPI WcaGetFormattedString( | |||
| 575 | } | 579 | } |
| 576 | else | 580 | else |
| 577 | { | 581 | { |
| 578 | hr = StrMaxLength(*ppwzData, &cch); | 582 | hr = StrMaxLength(*ppwzData, &cchMax); |
| 579 | ExitOnFailure(hr, "Failed to get previous size of property data string"); | 583 | ExitOnFailure(hr, "Failed to get previous size of property data string"); |
| 584 | |||
| 585 | cch = (DWORD)min(MAXDWORD, cchMax); | ||
| 580 | } | 586 | } |
| 581 | 587 | ||
| 582 | er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecord, *ppwzData, (DWORD *)&cch); | 588 | er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecord, *ppwzData, &cch); |
| 583 | if (ERROR_MORE_DATA == er) | 589 | if (ERROR_MORE_DATA == er) |
| 584 | { | 590 | { |
| 585 | hr = StrAlloc(ppwzData, ++cch); | 591 | hr = StrAlloc(ppwzData, ++cch); |
| 586 | ExitOnFailure(hr, "Failed to allocate string for formatted string: '%ls'", wzString); | 592 | ExitOnFailure(hr, "Failed to allocate string for formatted string: '%ls'", wzString); |
| 587 | 593 | ||
| 588 | er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecord, *ppwzData, (DWORD *)&cch); | 594 | er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecord, *ppwzData, &cch); |
| 589 | } | 595 | } |
| 590 | ExitOnWin32Error(er, hr, "Failed to get formatted string: '%ls'", wzString); | 596 | ExitOnWin32Error(er, hr, "Failed to get formatted string: '%ls'", wzString); |
| 591 | 597 | ||
| @@ -637,12 +643,13 @@ extern "C" HRESULT WIXAPI WcaGetTargetPath( | |||
| 637 | HRESULT hr = S_OK; | 643 | HRESULT hr = S_OK; |
| 638 | 644 | ||
| 639 | UINT er = ERROR_SUCCESS; | 645 | UINT er = ERROR_SUCCESS; |
| 640 | DWORD_PTR cch = 0; | 646 | DWORD cch = 0; |
| 647 | SIZE_T cchMax = 0; | ||
| 641 | 648 | ||
| 642 | if (!*ppwzData) | 649 | if (!*ppwzData) |
| 643 | { | 650 | { |
| 644 | WCHAR szEmpty[1] = L""; | 651 | WCHAR szEmpty[1] = L""; |
| 645 | er = ::MsiGetTargetPathW(WcaGetInstallHandle(), wzFolder, szEmpty, (DWORD*)&cch); | 652 | er = ::MsiGetTargetPathW(WcaGetInstallHandle(), wzFolder, szEmpty, &cch); |
| 646 | if (ERROR_MORE_DATA == er || ERROR_SUCCESS == er) | 653 | if (ERROR_MORE_DATA == er || ERROR_SUCCESS == er) |
| 647 | { | 654 | { |
| 648 | ++cch; //Add one for the null terminator | 655 | ++cch; //Add one for the null terminator |
| @@ -656,18 +663,20 @@ extern "C" HRESULT WIXAPI WcaGetTargetPath( | |||
| 656 | } | 663 | } |
| 657 | else | 664 | else |
| 658 | { | 665 | { |
| 659 | hr = StrMaxLength(*ppwzData, &cch); | 666 | hr = StrMaxLength(*ppwzData, &cchMax); |
| 660 | ExitOnFailure(hr, "Failed to get previous size of string"); | 667 | ExitOnFailure(hr, "Failed to get previous size of string"); |
| 668 | |||
| 669 | cch = (DWORD)min(MAXDWORD, cchMax); | ||
| 661 | } | 670 | } |
| 662 | 671 | ||
| 663 | er = ::MsiGetTargetPathW(WcaGetInstallHandle(), wzFolder, *ppwzData, (DWORD*)&cch); | 672 | er = ::MsiGetTargetPathW(WcaGetInstallHandle(), wzFolder, *ppwzData, &cch); |
| 664 | if (ERROR_MORE_DATA == er) | 673 | if (ERROR_MORE_DATA == er) |
| 665 | { | 674 | { |
| 666 | ++cch; | 675 | ++cch; |
| 667 | hr = StrAlloc(ppwzData, cch); | 676 | hr = StrAlloc(ppwzData, cch); |
| 668 | ExitOnFailure(hr, "Failed to allocate string for target path of folder: '%ls'", wzFolder); | 677 | ExitOnFailure(hr, "Failed to allocate string for target path of folder: '%ls'", wzFolder); |
| 669 | 678 | ||
| 670 | er = ::MsiGetTargetPathW(WcaGetInstallHandle(), wzFolder, *ppwzData, (DWORD*)&cch); | 679 | er = ::MsiGetTargetPathW(WcaGetInstallHandle(), wzFolder, *ppwzData, &cch); |
| 671 | } | 680 | } |
| 672 | ExitOnWin32Error(er, hr, "Failed to get target path for folder '%ls'", wzFolder); | 681 | ExitOnWin32Error(er, hr, "Failed to get target path for folder '%ls'", wzFolder); |
| 673 | 682 | ||
| @@ -802,12 +811,13 @@ extern "C" HRESULT WIXAPI WcaGetRecordString( | |||
| 802 | 811 | ||
| 803 | HRESULT hr = S_OK; | 812 | HRESULT hr = S_OK; |
| 804 | UINT er; | 813 | UINT er; |
| 805 | DWORD_PTR cch = 0; | 814 | DWORD cch = 0; |
| 815 | SIZE_T cchMax = 0; | ||
| 806 | 816 | ||
| 807 | if (!*ppwzData) | 817 | if (!*ppwzData) |
| 808 | { | 818 | { |
| 809 | WCHAR szEmpty[1] = L""; | 819 | WCHAR szEmpty[1] = L""; |
| 810 | er = ::MsiRecordGetStringW(hRec, uiField, szEmpty, (DWORD*)&cch); | 820 | er = ::MsiRecordGetStringW(hRec, uiField, szEmpty, &cch); |
| 811 | if (ERROR_MORE_DATA == er || ERROR_SUCCESS == er) | 821 | if (ERROR_MORE_DATA == er || ERROR_SUCCESS == er) |
| 812 | { | 822 | { |
| 813 | hr = StrAlloc(ppwzData, ++cch); | 823 | hr = StrAlloc(ppwzData, ++cch); |
| @@ -820,17 +830,19 @@ extern "C" HRESULT WIXAPI WcaGetRecordString( | |||
| 820 | } | 830 | } |
| 821 | else | 831 | else |
| 822 | { | 832 | { |
| 823 | hr = StrMaxLength(*ppwzData, &cch); | 833 | hr = StrMaxLength(*ppwzData, &cchMax); |
| 824 | ExitOnFailure(hr, "Failed to get previous size of string"); | 834 | ExitOnFailure(hr, "Failed to get previous size of string"); |
| 835 | |||
| 836 | cch = (DWORD)min(MAXDWORD, cchMax); | ||
| 825 | } | 837 | } |
| 826 | 838 | ||
| 827 | er = ::MsiRecordGetStringW(hRec, uiField, *ppwzData, (DWORD*)&cch); | 839 | er = ::MsiRecordGetStringW(hRec, uiField, *ppwzData, &cch); |
| 828 | if (ERROR_MORE_DATA == er) | 840 | if (ERROR_MORE_DATA == er) |
| 829 | { | 841 | { |
| 830 | hr = StrAlloc(ppwzData, ++cch); | 842 | hr = StrAlloc(ppwzData, ++cch); |
| 831 | ExitOnFailure(hr, "Failed to allocate memory for record string"); | 843 | ExitOnFailure(hr, "Failed to allocate memory for record string"); |
| 832 | 844 | ||
| 833 | er = ::MsiRecordGetStringW(hRec, uiField, *ppwzData, (DWORD*)&cch); | 845 | er = ::MsiRecordGetStringW(hRec, uiField, *ppwzData, &cch); |
| 834 | } | 846 | } |
| 835 | ExitOnWin32Error(er, hr, "Failed to get string from record"); | 847 | ExitOnWin32Error(er, hr, "Failed to get string from record"); |
| 836 | 848 | ||
| @@ -910,7 +922,8 @@ extern "C" HRESULT WIXAPI WcaGetRecordFormattedString( | |||
| 910 | 922 | ||
| 911 | HRESULT hr = S_OK; | 923 | HRESULT hr = S_OK; |
| 912 | UINT er; | 924 | UINT er; |
| 913 | DWORD_PTR cch = 0; | 925 | DWORD cch = 0; |
| 926 | SIZE_T cchMax = 0; | ||
| 914 | PMSIHANDLE hRecFormat; | 927 | PMSIHANDLE hRecFormat; |
| 915 | 928 | ||
| 916 | // get the format string | 929 | // get the format string |
| @@ -932,16 +945,18 @@ extern "C" HRESULT WIXAPI WcaGetRecordFormattedString( | |||
| 932 | ExitOnFailure(hr, "failed to set string to format record"); | 945 | ExitOnFailure(hr, "failed to set string to format record"); |
| 933 | 946 | ||
| 934 | // format the string | 947 | // format the string |
| 935 | hr = StrMaxLength(*ppwzData, &cch); | 948 | hr = StrMaxLength(*ppwzData, &cchMax); |
| 936 | ExitOnFailure(hr, "failed to get max length of string"); | 949 | ExitOnFailure(hr, "failed to get max length of string"); |
| 937 | 950 | ||
| 938 | er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecFormat, *ppwzData, (DWORD*)&cch); | 951 | cch = (DWORD)min(MAXDWORD, cchMax); |
| 952 | |||
| 953 | er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecFormat, *ppwzData, &cch); | ||
| 939 | if (ERROR_MORE_DATA == er) | 954 | if (ERROR_MORE_DATA == er) |
| 940 | { | 955 | { |
| 941 | hr = StrAlloc(ppwzData, ++cch); | 956 | hr = StrAlloc(ppwzData, ++cch); |
| 942 | ExitOnFailure(hr, "Failed to allocate memory for record string"); | 957 | ExitOnFailure(hr, "Failed to allocate memory for record string"); |
| 943 | 958 | ||
| 944 | er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecFormat, *ppwzData, (DWORD*)&cch); | 959 | er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecFormat, *ppwzData, &cch); |
| 945 | } | 960 | } |
| 946 | ExitOnWin32Error(er, hr, "Failed to format string"); | 961 | ExitOnWin32Error(er, hr, "Failed to format string"); |
| 947 | 962 | ||
| @@ -1273,7 +1288,7 @@ extern "C" HRESULT WIXAPI WcaReadIntegerFromCaData( | |||
| 1273 | ) | 1288 | ) |
| 1274 | { | 1289 | { |
| 1275 | LPCWSTR pwz = BreakDownCustomActionData(ppwzCustomActionData); | 1290 | LPCWSTR pwz = BreakDownCustomActionData(ppwzCustomActionData); |
| 1276 | if (!pwz || 0 == wcslen(pwz)) | 1291 | if (!pwz || !*pwz) |
| 1277 | return E_NOMOREITEMS; | 1292 | return E_NOMOREITEMS; |
| 1278 | 1293 | ||
| 1279 | *piResult = wcstol(pwz, NULL, 10); | 1294 | *piResult = wcstol(pwz, NULL, 10); |
| @@ -1319,24 +1334,34 @@ extern "C" HRESULT WIXAPI WcaWriteStringToCaData( | |||
| 1319 | { | 1334 | { |
| 1320 | HRESULT hr = S_OK; | 1335 | HRESULT hr = S_OK; |
| 1321 | WCHAR delim[] = {MAGIC_MULTISZ_DELIM, 0}; // magic char followed by NULL terminator | 1336 | WCHAR delim[] = {MAGIC_MULTISZ_DELIM, 0}; // magic char followed by NULL terminator |
| 1337 | SIZE_T cchString = 0; | ||
| 1338 | SIZE_T cchCustomActionData = 0; | ||
| 1339 | SIZE_T cchMax = 0; | ||
| 1322 | 1340 | ||
| 1323 | if (!ppwzCustomActionData) | 1341 | if (!ppwzCustomActionData) |
| 1324 | { | 1342 | { |
| 1325 | ExitFunction1(hr = E_INVALIDARG); | 1343 | ExitFunction1(hr = E_INVALIDARG); |
| 1326 | } | 1344 | } |
| 1327 | 1345 | ||
| 1328 | DWORD cchString = lstrlenW(wzString) + 1; // assume we'll be adding the delim | 1346 | hr = ::StringCchLengthW(wzString, STRSAFE_MAX_LENGTH, reinterpret_cast<size_t*>(&cchString)); |
| 1329 | DWORD_PTR cchCustomActionData = 0; | 1347 | ExitOnRootFailure(hr, "failed to get length of ca data string"); |
| 1348 | |||
| 1349 | ++cchString; // assume we'll be adding the delim | ||
| 1330 | 1350 | ||
| 1331 | if (*ppwzCustomActionData) | 1351 | if (*ppwzCustomActionData) |
| 1332 | { | 1352 | { |
| 1333 | hr = StrMaxLength(*ppwzCustomActionData, &cchCustomActionData); | 1353 | hr = StrMaxLength(*ppwzCustomActionData, &cchCustomActionData); |
| 1334 | ExitOnFailure(hr, "failed to get length of custom action data"); | 1354 | ExitOnFailure(hr, "failed to get max length of custom action data"); |
| 1355 | |||
| 1356 | hr = ::StringCchLengthW(*ppwzCustomActionData, STRSAFE_MAX_LENGTH, reinterpret_cast<size_t*>(&cchMax)); | ||
| 1357 | ExitOnRootFailure(hr, "failed to get length of custom action data"); | ||
| 1335 | } | 1358 | } |
| 1336 | 1359 | ||
| 1337 | if ((cchCustomActionData - lstrlenW(*ppwzCustomActionData)) < cchString + 1) | 1360 | if ((cchCustomActionData - cchMax) < cchString + 1) |
| 1338 | { | 1361 | { |
| 1339 | cchCustomActionData += cchString + 1 + 255; // add 255 for good measure | 1362 | cchCustomActionData += cchString + 1 + 255; // add 255 for good measure |
| 1363 | cchCustomActionData = min(STRSAFE_MAX_LENGTH, cchCustomActionData); | ||
| 1364 | |||
| 1340 | hr = StrAlloc(ppwzCustomActionData, cchCustomActionData); | 1365 | hr = StrAlloc(ppwzCustomActionData, cchCustomActionData); |
| 1341 | ExitOnFailure(hr, "Failed to allocate memory for CustomActionData string"); | 1366 | ExitOnFailure(hr, "Failed to allocate memory for CustomActionData string"); |
| 1342 | } | 1367 | } |
| @@ -1344,11 +1369,11 @@ extern "C" HRESULT WIXAPI WcaWriteStringToCaData( | |||
| 1344 | if (**ppwzCustomActionData) // if data exists toss the delimiter on before adding more to the end | 1369 | if (**ppwzCustomActionData) // if data exists toss the delimiter on before adding more to the end |
| 1345 | { | 1370 | { |
| 1346 | hr = ::StringCchCatW(*ppwzCustomActionData, cchCustomActionData, delim); | 1371 | hr = ::StringCchCatW(*ppwzCustomActionData, cchCustomActionData, delim); |
| 1347 | ExitOnFailure(hr, "Failed to concatenate CustomActionData string"); | 1372 | ExitOnRootFailure(hr, "Failed to concatenate CustomActionData string"); |
| 1348 | } | 1373 | } |
| 1349 | 1374 | ||
| 1350 | hr = ::StringCchCatW(*ppwzCustomActionData, cchCustomActionData, wzString); | 1375 | hr = ::StringCchCatW(*ppwzCustomActionData, cchCustomActionData, wzString); |
| 1351 | ExitOnFailure(hr, "Failed to concatenate CustomActionData string"); | 1376 | ExitOnRootFailure(hr, "Failed to concatenate CustomActionData string"); |
| 1352 | 1377 | ||
| 1353 | LExit: | 1378 | LExit: |
| 1354 | return hr; | 1379 | return hr; |
diff --git a/src/wcautil/wcawrapquery.cpp b/src/wcautil/wcawrapquery.cpp index f04da10d..a3b593fd 100644 --- a/src/wcautil/wcawrapquery.cpp +++ b/src/wcautil/wcawrapquery.cpp | |||
| @@ -88,7 +88,7 @@ eColumnDataType WIXAPI GetDataTypeFromString( | |||
| 88 | LPCWSTR pwzTypeString | 88 | LPCWSTR pwzTypeString |
| 89 | ) | 89 | ) |
| 90 | { | 90 | { |
| 91 | if (NULL == pwzTypeString || 0 == wcslen(pwzTypeString)) | 91 | if (!pwzTypeString || !*pwzTypeString) |
| 92 | { | 92 | { |
| 93 | return cdtUnknown; | 93 | return cdtUnknown; |
| 94 | } | 94 | } |
| @@ -350,7 +350,7 @@ HRESULT WIXAPI WcaWrapQuery( | |||
| 350 | hr = WcaGetRecordString(hRec, dwComponentColumn, &pwzData); | 350 | hr = WcaGetRecordString(hRec, dwComponentColumn, &pwzData); |
| 351 | ExitOnFailure(hr, "Failed to get component from column %d while adding extra columns", dwComponentColumn); | 351 | ExitOnFailure(hr, "Failed to get component from column %d while adding extra columns", dwComponentColumn); |
| 352 | 352 | ||
| 353 | if (0 == lstrlenW(pwzData)) | 353 | if (!pwzData || !*pwzData) |
| 354 | { | 354 | { |
| 355 | // If no component was provided, set these both to zero as though a structure to store them were allocated with memory zero'd out | 355 | // If no component was provided, set these both to zero as though a structure to store them were allocated with memory zero'd out |
| 356 | isInstalled = (INSTALLSTATE)0; | 356 | isInstalled = (INSTALLSTATE)0; |
