diff options
Diffstat (limited to 'src/wcautil/wcawrap.cpp')
-rw-r--r-- | src/wcautil/wcawrap.cpp | 89 |
1 files changed, 57 insertions, 32 deletions
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; |