[PATCH v3 0/1] MR3410: advpack: Add nullcheck for parameter that can be null (Coverity)
-- v3: advpack: Add nullchecks for parameters that can be null (Coverity) https://gitlab.winehq.org/wine/wine/-/merge_requests/3410
From: Fabian Maurer <dark.shadow4(a)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 b32a6f4c972..8bbed08f57f 100644 --- a/dlls/advpack/install.c +++ b/dlls/advpack/install.c @@ -574,7 +574,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) @@ -626,9 +626,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 bdf02c5a397..18dc6cfb351 100644 --- a/dlls/advpack/tests/install.c +++ b/dlls/advpack/tests/install.c @@ -262,6 +262,38 @@ static void test_LaunchINFSectionEx(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(0, 0, 0); Crashes on windows */ + + hr = ExecuteCabA(0, &cabinfoa, 0); + ok(hr == E_INVALIDARG, "Got %lx\n", hr); + + cabinfoa.pszInf = str_empty; + hr = ExecuteCabA(0, &cabinfoa, 0); + ok(hr == E_INVALIDARG, "Got %lx\n", hr); + + /* ExecuteCabW */ + + hr = ExecuteCabW(0, 0, 0); + ok(hr == E_INVALIDARG, "Got %lx\n", hr); + + hr = ExecuteCabW(0, &cabinfow, 0); + ok(hr == E_INVALIDARG, "Got %lx\n", hr); + + cabinfow.pszInf = wstr_empty; + hr = ExecuteCabW(0, &cabinfow, 0); + ok(hr == E_INVALIDARG, "Got %lx\n", hr); +} + START_TEST(install) { DWORD len; @@ -289,6 +321,7 @@ START_TEST(install) test_RunSetupCommand(); test_LaunchINFSection(); test_LaunchINFSectionEx(); + test_ExecuteCab(); FreeLibrary(hAdvPack); SetCurrentDirectoryA(prev_path); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/3410
participants (2)
-
Fabian Maurer -
Fabian Maurer (@DarkShadow44)