Robert Shearman : ole32: Add validation of parameters to CoGetClassObject and make sure to initialise ppv to NULL .

Alexandre Julliard julliard at wine.codeweavers.com
Fri Jul 14 10:50:29 CDT 2006


Module: wine
Branch: refs/heads/master
Commit: 69e10bf1ed94ef933a6e627a3dd0167a065e9598
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=69e10bf1ed94ef933a6e627a3dd0167a065e9598

Author: Robert Shearman <rob at codeweavers.com>
Date:   Fri Jul 14 00:02:24 2006 +0100

ole32: Add validation of parameters to CoGetClassObject and make sure to initialise ppv to NULL.

---

 dlls/ole32/compobj.c       |   11 +++++++++++
 dlls/ole32/tests/compobj.c |   12 ++++++++++++
 2 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/dlls/ole32/compobj.c b/dlls/ole32/compobj.c
index 4efa235..db0fcbe 100644
--- a/dlls/ole32/compobj.c
+++ b/dlls/ole32/compobj.c
@@ -1618,6 +1618,17 @@ HRESULT WINAPI CoGetClassObject(
 
     TRACE("\n\tCLSID:\t%s,\n\tIID:\t%s\n", debugstr_guid(rclsid), debugstr_guid(iid));
 
+    if (!ppv)
+        return E_INVALIDARG;
+
+    *ppv = NULL;
+
+    if (!COM_CurrentApt())
+    {
+        ERR("apartment not initialised\n");
+        return CO_E_NOTINITIALIZED;
+    }
+
     if (pServerInfo) {
 	FIXME("\tpServerInfo: name=%s\n",debugstr_w(pServerInfo->pwszName));
 	FIXME("\t\tpAuthInfo=%p\n",pServerInfo->pAuthInfo);
diff --git a/dlls/ole32/tests/compobj.c b/dlls/ole32/tests/compobj.c
index 06bf381..9164be8 100644
--- a/dlls/ole32/tests/compobj.c
+++ b/dlls/ole32/tests/compobj.c
@@ -100,6 +100,17 @@ static void test_CoCreateInstance(void)
     ok(hr == CO_E_NOTINITIALIZED, "CoCreateInstance should have returned CO_E_NOTINITIALIZED instead of 0x%08lx\n", hr);
 }
 
+static void test_CoGetClassObject(void)
+{
+    IUnknown *pUnk = (IUnknown *)0xdeadbeef;
+    HRESULT hr = CoGetClassObject(&CLSID_MyComputer, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void **)&pUnk);
+    ok(hr == CO_E_NOTINITIALIZED, "CoGetClassObject should have returned CO_E_NOTINITIALIZED instead of 0x%08lx\n", hr);
+    ok(pUnk == NULL, "CoGetClassObject should have changed the passed in pointer to NULL, instead of %p\n", pUnk);
+
+    hr = CoGetClassObject(&CLSID_MyComputer, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, NULL);
+    ok(hr == E_INVALIDARG, "CoGetClassObject should have returned E_INVALIDARG instead of 0x%08lx\n", hr);
+}
+
 static ATOM register_dummy_class(void)
 {
     WNDCLASS wc =
@@ -138,4 +149,5 @@ START_TEST(compobj)
     test_CLSIDFromString();
     test_CoCreateInstance();
     test_ole_menu();
+    test_CoGetClassObject();
 }




More information about the wine-cvs mailing list