-- v7: advpack: Add nullchecks for parameters that can be null (Coverity)
From: Fabian Maurer dark.shadow4@web.de
--- dlls/advpack/install.c | 7 +++++-- dlls/advpack/tests/install.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/dlls/advpack/install.c b/dlls/advpack/install.c index 81ceebbe7aa..b9293f6ac19 100644 --- a/dlls/advpack/install.c +++ b/dlls/advpack/install.c @@ -582,7 +582,7 @@ HRESULT WINAPI ExecuteCabA(HWND hwnd, CABINFOA* pCab, LPVOID pReserved)
TRACE("(%p, %p, %p)\n", hwnd, pCab, pReserved);
- if (!pCab) + if (!pCab || !pCab->pszInf) return E_INVALIDARG;
if (pCab->pszCab) @@ -634,9 +634,12 @@ HRESULT WINAPI ExecuteCabW(HWND hwnd, CABINFOW* pCab, LPVOID pReserved)
TRACE("(%p, %p, %p)\n", hwnd, pCab, pReserved);
+ if (!pCab || !pCab->pszInf || !*pCab->pszInf) + return E_INVALIDARG; + ZeroMemory(&info, sizeof(ADVInfo));
- if ((pCab->pszCab && *pCab->pszCab) && (pCab->pszInf && *pCab->pszInf) && *pCab->szSrcPath) + if ((pCab->pszCab && *pCab->pszCab) && *pCab->szSrcPath) { TRACE("pszCab: %s, pszInf: %s, szSrcPath: %s\n", debugstr_w(pCab->pszCab), debugstr_w(pCab->pszInf), debugstr_w(pCab->szSrcPath)); diff --git a/dlls/advpack/tests/install.c b/dlls/advpack/tests/install.c index 7d747b1f018..41cb7e9fbad 100644 --- a/dlls/advpack/tests/install.c +++ b/dlls/advpack/tests/install.c @@ -357,6 +357,38 @@ static void test_RegisterOCXs(void) DeleteFileA("test.inf"); }
+static void test_ExecuteCab(void) +{ + HRESULT hr; + WCHAR wstr_empty[1] = {0}; + char str_empty[1] = {0}; + CABINFOA cabinfoa = {0}; + CABINFOW cabinfow = {0}; + + /* ExecuteCabA */ + + /* ExecuteCabA(NULL, NULL, NULL); Crashes on windows */ + + hr = ExecuteCabA(NULL, &cabinfoa, NULL); + ok(hr == E_INVALIDARG, "Got %lx\n", hr); + + cabinfoa.pszInf = str_empty; + hr = ExecuteCabA(NULL, &cabinfoa, NULL); + ok(hr == E_INVALIDARG, "Got %lx\n", hr); + + /* ExecuteCabW */ + + hr = ExecuteCabW(NULL, NULL, NULL); + ok(hr == E_INVALIDARG, "Got %lx\n", hr); + + hr = ExecuteCabW(NULL, &cabinfow, NULL); + ok(hr == E_INVALIDARG, "Got %lx\n", hr); + + cabinfow.pszInf = wstr_empty; + hr = ExecuteCabW(NULL, &cabinfow, NULL); + ok(hr == E_INVALIDARG, "Got %lx\n", hr); +} + START_TEST(install) { DWORD len; @@ -385,6 +417,7 @@ START_TEST(install) test_LaunchINFSection(); test_LaunchINFSectionEx(); test_RegisterOCXs(); + test_ExecuteCab();
FreeLibrary(hAdvPack); SetCurrentDirectoryA(prev_path);