@joebigelow / wix / commits / 46897fef

Clean up more 32-bit assumptions.

Sean Hall committed Apr 28, 2021 at 18:12 UTC 46897fefd6aef4168f35c1f366c833d715c3bdaa
6 files changed +72 -65
src/wcautil/packages.config
+1 -1
@@ -1,5 +1,5 @@
1 <?xml version="1.0" encoding="utf-8"?>
2 <packages>
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
src/wcautil/wcalog.cpp
+3 -3
@@ -54,10 +54,10 @@ BOOL WIXAPI IsVerboseLogging()
54 // if the property wasn't set, check the MsiLogging property (MSI 4.0+)
55 HRESULT hr = WcaGetProperty(L"MsiLogging", &pwzMsiLogging);
56 ExitOnFailure(hr, "failed to get MsiLogging property");
57 - int cchMsiLogging = lstrlenW(pwzMsiLogging);
58 - if (0 < cchMsiLogging)
57 +
58 + if (pwzMsiLogging)
59 {
60 - for (int i = 0; i < cchMsiLogging; i++)
60 + for (int i = 0; pwzMsiLogging[i]; i++)
61 {
62 if (L'v' == pwzMsiLogging[i] || L'V' == pwzMsiLogging[i])
63 {
src/wcautil/wcascript.cpp
+7 -25
@@ -247,9 +247,8 @@ extern "C" HRESULT WIXAPI WcaCaScriptWriteString(
247 {
248 HRESULT hr = S_OK;
249 DWORD cbFile = 0;
250 - DWORD cbWrite = 0;
251 - DWORD cbTotalWritten = 0;
250 WCHAR delim[] = { MAGIC_MULTISZ_DELIM }; // magic char followed by NULL terminator
251 + SIZE_T cch = 0;
252
253 cbFile = ::SetFilePointer(hScript->hScriptFile, 0, NULL, FILE_END);
254 if (INVALID_SET_FILE_POINTER == cbFile)
@@ -261,32 +260,15 @@ extern "C" HRESULT WIXAPI WcaCaScriptWriteString(
260 // before adding our new data on the end of the file.
261 if (0 < cbFile)
262 {
264 - cbWrite = sizeof(delim);
265 - cbTotalWritten = 0;
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 - }
263 + hr = FileWriteHandle(hScript->hScriptFile, reinterpret_cast<LPCBYTE>(delim), sizeof(delim));
264 + ExitOnFailure(hr, "Failed to write data to ca script.");
265 }
266
278 - cbWrite = lstrlenW(wzValue) * sizeof(WCHAR);
279 - cbTotalWritten = 0;
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 - }
267 + hr = ::StringCchLengthW(wzValue, STRSAFE_MAX_CCH, reinterpret_cast<size_t*>(&cch));
268 + ExitOnRootFailure(hr, "Failed to get length of ca script string.");
269
288 - cbTotalWritten += cbWritten;
289 - }
270 + hr = FileWriteHandle(hScript->hScriptFile, reinterpret_cast<LPCBYTE>(wzValue), static_cast<DWORD>(cch) * sizeof(WCHAR));
271 + ExitOnFailure(hr, "Failed to write data to ca script.");
272
273 LExit:
274 return hr;
src/wcautil/wcautil.vcxproj
+2 -2
@@ -1,7 +1,7 @@
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. -->
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">
6 <ProjectConfiguration Include="Debug|ARM64">
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>
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'))" />
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>
94 </Project>
\ No newline at end of file
src/wcautil/wcawrap.cpp
+57 -32
@@ -467,12 +467,13 @@ extern "C" HRESULT WIXAPI WcaGetProperty(
467
468 HRESULT hr = S_OK;
469 UINT er = ERROR_SUCCESS;
470 - DWORD_PTR cch = 0;
470 + DWORD cch = 0;
471 + SIZE_T cchMax = 0;
472
473 if (!*ppwzData)
474 {
475 WCHAR szEmpty[1] = L"";
475 - er = ::MsiGetPropertyW(WcaGetInstallHandle(), wzProperty, szEmpty, (DWORD *)&cch);
476 + er = ::MsiGetPropertyW(WcaGetInstallHandle(), wzProperty, szEmpty, &cch);
477 if (ERROR_MORE_DATA == er || ERROR_SUCCESS == er)
478 {
479 hr = StrAlloc(ppwzData, ++cch);
@@ -481,22 +482,24 @@ extern "C" HRESULT WIXAPI WcaGetProperty(
482 {
483 hr = HRESULT_FROM_WIN32(er);
484 }
484 - ExitOnFailure(hr, "Failed to allocate string for Property '%ls'", wzProperty);
485 + ExitOnRootFailure(hr, "Failed to allocate string for Property '%ls'", wzProperty);
486 }
487 else
488 {
488 - hr = StrMaxLength(*ppwzData, &cch);
489 + hr = StrMaxLength(*ppwzData, &cchMax);
490 ExitOnFailure(hr, "Failed to get previous size of property data string.");
491 +
492 + cch = (DWORD)min(MAXDWORD, cchMax);
493 }
494
492 - er = ::MsiGetPropertyW(WcaGetInstallHandle(), wzProperty, *ppwzData, (DWORD *)&cch);
495 + er = ::MsiGetPropertyW(WcaGetInstallHandle(), wzProperty, *ppwzData, &cch);
496 if (ERROR_MORE_DATA == er)
497 {
498 Assert(*ppwzData);
499 hr = StrAlloc(ppwzData, ++cch);
500 ExitOnFailure(hr, "Failed to allocate string for Property '%ls'", wzProperty);
501
499 - er = ::MsiGetPropertyW(WcaGetInstallHandle(), wzProperty, *ppwzData, (DWORD *)&cch);
502 + er = ::MsiGetPropertyW(WcaGetInstallHandle(), wzProperty, *ppwzData, &cch);
503 }
504 ExitOnWin32Error(er, hr, "Failed to get data for property '%ls'", wzProperty);
505
@@ -554,7 +557,8 @@ extern "C" HRESULT WIXAPI WcaGetFormattedString(
557 HRESULT hr = S_OK;
558 UINT er = ERROR_SUCCESS;
559 PMSIHANDLE hRecord = ::MsiCreateRecord(1);
557 - DWORD_PTR cch = 0;
560 + DWORD cch = 0;
561 + SIZE_T cchMax = 0;
562
563 er = ::MsiRecordSetStringW(hRecord, 0, wzString);
564 ExitOnWin32Error(er, hr, "Failed to set record field 0 with '%ls'", wzString);
@@ -562,7 +566,7 @@ extern "C" HRESULT WIXAPI WcaGetFormattedString(
566 if (!*ppwzData)
567 {
568 WCHAR szEmpty[1] = L"";
565 - er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecord, szEmpty, (DWORD *)&cch);
569 + er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecord, szEmpty, &cch);
570 if (ERROR_MORE_DATA == er || ERROR_SUCCESS == er)
571 {
572 hr = StrAlloc(ppwzData, ++cch);
@@ -575,17 +579,19 @@ extern "C" HRESULT WIXAPI WcaGetFormattedString(
579 }
580 else
581 {
578 - hr = StrMaxLength(*ppwzData, &cch);
582 + hr = StrMaxLength(*ppwzData, &cchMax);
583 ExitOnFailure(hr, "Failed to get previous size of property data string");
584 +
585 + cch = (DWORD)min(MAXDWORD, cchMax);
586 }
587
582 - er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecord, *ppwzData, (DWORD *)&cch);
588 + er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecord, *ppwzData, &cch);
589 if (ERROR_MORE_DATA == er)
590 {
591 hr = StrAlloc(ppwzData, ++cch);
592 ExitOnFailure(hr, "Failed to allocate string for formatted string: '%ls'", wzString);
593
588 - er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecord, *ppwzData, (DWORD *)&cch);
594 + er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecord, *ppwzData, &cch);
595 }
596 ExitOnWin32Error(er, hr, "Failed to get formatted string: '%ls'", wzString);
597
@@ -637,12 +643,13 @@ extern "C" HRESULT WIXAPI WcaGetTargetPath(
643 HRESULT hr = S_OK;
644
645 UINT er = ERROR_SUCCESS;
640 - DWORD_PTR cch = 0;
646 + DWORD cch = 0;
647 + SIZE_T cchMax = 0;
648
649 if (!*ppwzData)
650 {
651 WCHAR szEmpty[1] = L"";
645 - er = ::MsiGetTargetPathW(WcaGetInstallHandle(), wzFolder, szEmpty, (DWORD*)&cch);
652 + er = ::MsiGetTargetPathW(WcaGetInstallHandle(), wzFolder, szEmpty, &cch);
653 if (ERROR_MORE_DATA == er || ERROR_SUCCESS == er)
654 {
655 ++cch; //Add one for the null terminator
@@ -656,18 +663,20 @@ extern "C" HRESULT WIXAPI WcaGetTargetPath(
663 }
664 else
665 {
659 - hr = StrMaxLength(*ppwzData, &cch);
666 + hr = StrMaxLength(*ppwzData, &cchMax);
667 ExitOnFailure(hr, "Failed to get previous size of string");
668 +
669 + cch = (DWORD)min(MAXDWORD, cchMax);
670 }
671
663 - er = ::MsiGetTargetPathW(WcaGetInstallHandle(), wzFolder, *ppwzData, (DWORD*)&cch);
672 + er = ::MsiGetTargetPathW(WcaGetInstallHandle(), wzFolder, *ppwzData, &cch);
673 if (ERROR_MORE_DATA == er)
674 {
675 ++cch;
676 hr = StrAlloc(ppwzData, cch);
677 ExitOnFailure(hr, "Failed to allocate string for target path of folder: '%ls'", wzFolder);
678
670 - er = ::MsiGetTargetPathW(WcaGetInstallHandle(), wzFolder, *ppwzData, (DWORD*)&cch);
679 + er = ::MsiGetTargetPathW(WcaGetInstallHandle(), wzFolder, *ppwzData, &cch);
680 }
681 ExitOnWin32Error(er, hr, "Failed to get target path for folder '%ls'", wzFolder);
682
@@ -802,12 +811,13 @@ extern "C" HRESULT WIXAPI WcaGetRecordString(
811
812 HRESULT hr = S_OK;
813 UINT er;
805 - DWORD_PTR cch = 0;
814 + DWORD cch = 0;
815 + SIZE_T cchMax = 0;
816
817 if (!*ppwzData)
818 {
819 WCHAR szEmpty[1] = L"";
810 - er = ::MsiRecordGetStringW(hRec, uiField, szEmpty, (DWORD*)&cch);
820 + er = ::MsiRecordGetStringW(hRec, uiField, szEmpty, &cch);
821 if (ERROR_MORE_DATA == er || ERROR_SUCCESS == er)
822 {
823 hr = StrAlloc(ppwzData, ++cch);
@@ -820,17 +830,19 @@ extern "C" HRESULT WIXAPI WcaGetRecordString(
830 }
831 else
832 {
823 - hr = StrMaxLength(*ppwzData, &cch);
833 + hr = StrMaxLength(*ppwzData, &cchMax);
834 ExitOnFailure(hr, "Failed to get previous size of string");
835 +
836 + cch = (DWORD)min(MAXDWORD, cchMax);
837 }
838
827 - er = ::MsiRecordGetStringW(hRec, uiField, *ppwzData, (DWORD*)&cch);
839 + er = ::MsiRecordGetStringW(hRec, uiField, *ppwzData, &cch);
840 if (ERROR_MORE_DATA == er)
841 {
842 hr = StrAlloc(ppwzData, ++cch);
843 ExitOnFailure(hr, "Failed to allocate memory for record string");
844
833 - er = ::MsiRecordGetStringW(hRec, uiField, *ppwzData, (DWORD*)&cch);
845 + er = ::MsiRecordGetStringW(hRec, uiField, *ppwzData, &cch);
846 }
847 ExitOnWin32Error(er, hr, "Failed to get string from record");
848
@@ -910,7 +922,8 @@ extern "C" HRESULT WIXAPI WcaGetRecordFormattedString(
922
923 HRESULT hr = S_OK;
924 UINT er;
913 - DWORD_PTR cch = 0;
925 + DWORD cch = 0;
926 + SIZE_T cchMax = 0;
927 PMSIHANDLE hRecFormat;
928
929 // get the format string
@@ -932,16 +945,18 @@ extern "C" HRESULT WIXAPI WcaGetRecordFormattedString(
945 ExitOnFailure(hr, "failed to set string to format record");
946
947 // format the string
935 - hr = StrMaxLength(*ppwzData, &cch);
948 + hr = StrMaxLength(*ppwzData, &cchMax);
949 ExitOnFailure(hr, "failed to get max length of string");
950
938 - er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecFormat, *ppwzData, (DWORD*)&cch);
951 + cch = (DWORD)min(MAXDWORD, cchMax);
952 +
953 + er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecFormat, *ppwzData, &cch);
954 if (ERROR_MORE_DATA == er)
955 {
956 hr = StrAlloc(ppwzData, ++cch);
957 ExitOnFailure(hr, "Failed to allocate memory for record string");
958
944 - er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecFormat, *ppwzData, (DWORD*)&cch);
959 + er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecFormat, *ppwzData, &cch);
960 }
961 ExitOnWin32Error(er, hr, "Failed to format string");
962
@@ -1273,7 +1288,7 @@ extern "C" HRESULT WIXAPI WcaReadIntegerFromCaData(
1288 )
1289 {
1290 LPCWSTR pwz = BreakDownCustomActionData(ppwzCustomActionData);
1276 - if (!pwz || 0 == wcslen(pwz))
1291 + if (!pwz || !*pwz)
1292 return E_NOMOREITEMS;
1293
1294 *piResult = wcstol(pwz, NULL, 10);
@@ -1319,24 +1334,34 @@ extern "C" HRESULT WIXAPI WcaWriteStringToCaData(
1334 {
1335 HRESULT hr = S_OK;
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;
1340
1341 if (!ppwzCustomActionData)
1342 {
1343 ExitFunction1(hr = E_INVALIDARG);
1344 }
1345
1328 - DWORD cchString = lstrlenW(wzString) + 1; // assume we'll be adding the delim
1329 - DWORD_PTR cchCustomActionData = 0;
1346 + hr = ::StringCchLengthW(wzString, STRSAFE_MAX_LENGTH, reinterpret_cast<size_t*>(&cchString));
1347 + ExitOnRootFailure(hr, "failed to get length of ca data string");
1348 +
1349 + ++cchString; // assume we'll be adding the delim
1350
1351 if (*ppwzCustomActionData)
1352 {
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");
1358 }
1359
1337 - if ((cchCustomActionData - lstrlenW(*ppwzCustomActionData)) < cchString + 1)
1360 + if ((cchCustomActionData - cchMax) < cchString + 1)
1361 {
1362 cchCustomActionData += cchString + 1 + 255; // add 255 for good measure
1363 + cchCustomActionData = min(STRSAFE_MAX_LENGTH, cchCustomActionData);
1364 +
1365 hr = StrAlloc(ppwzCustomActionData, cchCustomActionData);
1366 ExitOnFailure(hr, "Failed to allocate memory for CustomActionData string");
1367 }
@@ -1344,11 +1369,11 @@ extern "C" HRESULT WIXAPI WcaWriteStringToCaData(
1369 if (**ppwzCustomActionData) // if data exists toss the delimiter on before adding more to the end
1370 {
1371 hr = ::StringCchCatW(*ppwzCustomActionData, cchCustomActionData, delim);
1347 - ExitOnFailure(hr, "Failed to concatenate CustomActionData string");
1372 + ExitOnRootFailure(hr, "Failed to concatenate CustomActionData string");
1373 }
1374
1375 hr = ::StringCchCatW(*ppwzCustomActionData, cchCustomActionData, wzString);
1351 - ExitOnFailure(hr, "Failed to concatenate CustomActionData string");
1376 + ExitOnRootFailure(hr, "Failed to concatenate CustomActionData string");
1377
1378 LExit:
1379 return hr;
src/wcautil/wcawrapquery.cpp
+2 -2
@@ -88,7 +88,7 @@ eColumnDataType WIXAPI GetDataTypeFromString(
88 LPCWSTR pwzTypeString
89 )
90 {
91 - if (NULL == pwzTypeString || 0 == wcslen(pwzTypeString))
91 + if (!pwzTypeString || !*pwzTypeString)
92 {
93 return cdtUnknown;
94 }
@@ -350,7 +350,7 @@ HRESULT WIXAPI WcaWrapQuery(
350 hr = WcaGetRecordString(hRec, dwComponentColumn, &pwzData);
351 ExitOnFailure(hr, "Failed to get component from column %d while adding extra columns", dwComponentColumn);
352
353 - if (0 == lstrlenW(pwzData))
353 + if (!pwzData || !*pwzData)
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
356 isInstalled = (INSTALLSTATE)0;