From 1b6adcb7216a6b4a0706ac7255f3ddb832656127 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Tue, 24 Apr 2018 22:27:41 -0500 Subject: [PATCH] msi: Handle some invalid parameters in MsiGetFeatureCost(). Signed-off-by: Zebediah Figura Signed-off-by: Hans Leidekker Signed-off-by: Alexandre Julliard --- dlls/msi/install.c | 9 +++++++++ dlls/msi/tests/package.c | 18 ++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/dlls/msi/install.c b/dlls/msi/install.c index b9290b4a8d0..63aed1eeebe 100644 --- a/dlls/msi/install.c +++ b/dlls/msi/install.c @@ -1061,6 +1061,9 @@ UINT WINAPI MsiGetFeatureCostW(MSIHANDLE hInstall, LPCWSTR szFeature, TRACE("(%d %s %i %i %p)\n", hInstall, debugstr_w(szFeature), iCostTree, iState, piCost); + if (!szFeature) + return ERROR_INVALID_PARAMETER; + package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE); if (!package) { @@ -1090,6 +1093,12 @@ UINT WINAPI MsiGetFeatureCostW(MSIHANDLE hInstall, LPCWSTR szFeature, return ERROR_SUCCESS; } + if (!piCost) + { + msiobj_release( &package->hdr ); + return ERROR_INVALID_PARAMETER; + } + feature = msi_get_loaded_feature(package, szFeature); if (feature) diff --git a/dlls/msi/tests/package.c b/dlls/msi/tests/package.c index c2e2106c38b..d26e2fdb56f 100644 --- a/dlls/msi/tests/package.c +++ b/dlls/msi/tests/package.c @@ -8479,7 +8479,7 @@ static void test_MsiApplyPatch(void) ok(r == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %u\n", r); } -static void test_MsiEnumComponentCosts(void) +static void test_costs(void) { MSIHANDLE hdb, hpkg; char package[12], drive[3]; @@ -8662,6 +8662,20 @@ static void test_MsiEnumComponentCosts(void) r = MsiEnumComponentCostsA( hpkg, "", 1, INSTALLSTATE_UNKNOWN, drive, &len, &cost, &temp ); ok( r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %u\n", r ); + /* test MsiGetFeatureCost */ + cost = 0xdead; + r = MsiGetFeatureCostA( hpkg, NULL, MSICOSTTREE_SELFONLY, INSTALLSTATE_LOCAL, &cost ); + ok( r == ERROR_INVALID_PARAMETER, "got %u\n", r); + ok( cost == 0xdead, "got %d\n", cost ); + + r = MsiGetFeatureCostA( hpkg, "one", MSICOSTTREE_SELFONLY, INSTALLSTATE_LOCAL, NULL ); + ok( r == ERROR_INVALID_PARAMETER, "got %u\n", r); + + cost = 0xdead; + r = MsiGetFeatureCostA( hpkg, "one", MSICOSTTREE_SELFONLY, INSTALLSTATE_LOCAL, &cost ); + ok( !r, "got %u\n", r); + ok( cost == 8, "got %d\n", cost ); + MsiCloseHandle( hpkg ); error: MsiCloseHandle( hdb ); @@ -9702,7 +9716,7 @@ START_TEST(package) test_MsiSetProperty(); test_MsiApplyMultiplePatches(); test_MsiApplyPatch(); - test_MsiEnumComponentCosts(); + test_costs(); test_MsiDatabaseCommit(); test_externalui(); test_externalui_message(); -- 2.11.4.GIT