From 5a3b87a0fd3d643106dbc3cbd6ebef69b61401e8 Mon Sep 17 00:00:00 2001 From: Alex Henrie Date: Wed, 5 Jul 2017 23:01:22 -0600 Subject: [PATCH] ole32: Avoid null pointer dereferences in CoGetTreatAsClass. Signed-off-by: Alex Henrie Signed-off-by: Huw Davies Signed-off-by: Alexandre Julliard --- dlls/ole32/compobj.c | 4 ++++ dlls/ole32/tests/compobj.c | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/dlls/ole32/compobj.c b/dlls/ole32/compobj.c index 1ce9cec6e53..60244485249 100644 --- a/dlls/ole32/compobj.c +++ b/dlls/ole32/compobj.c @@ -3825,6 +3825,10 @@ HRESULT WINAPI CoGetTreatAsClass(REFCLSID clsidOld, LPCLSID clsidNew) LONG len = sizeof(szClsidNew); TRACE("(%s,%p)\n", debugstr_guid(clsidOld), clsidNew); + + if (!clsidOld || !clsidNew) + return E_INVALIDARG; + *clsidNew = *clsidOld; /* copy over old value */ res = COM_OpenKeyForCLSID(clsidOld, wszTreatAs, KEY_READ, &hkey); diff --git a/dlls/ole32/tests/compobj.c b/dlls/ole32/tests/compobj.c index e585a4600ce..feb1d72eace 100644 --- a/dlls/ole32/tests/compobj.c +++ b/dlls/ole32/tests/compobj.c @@ -2176,10 +2176,18 @@ static void test_TreatAsClass(void) win_skip("CoGetTreatAsClass not present\n"); return; } + hr = pCoGetTreatAsClass(&deadbeef,&out); ok (hr == S_FALSE, "expected S_FALSE got %x\n",hr); ok (IsEqualGUID(&out,&deadbeef), "expected to get same clsid back\n"); + hr = pCoGetTreatAsClass(NULL, &out); + ok(hr == E_INVALIDARG, "expected E_INVALIDARG got %08x\n", hr); + ok(IsEqualGUID(&out, &deadbeef), "expected no change to the clsid\n"); + + hr = pCoGetTreatAsClass(&deadbeef, NULL); + ok(hr == E_INVALIDARG, "expected E_INVALIDARG got %08x\n", hr); + lr = RegOpenKeyExA(HKEY_CLASSES_ROOT, "CLSID", 0, KEY_READ, &clsidkey); ok(!lr, "Couldn't open CLSID key, error %d\n", lr); -- 2.11.4.GIT