[PATCH] ole32: Zero out pointer in CreateFileMoniker() on error

Nikolay Sivov nsivov at codeweavers.com
Tue Dec 29 05:17:27 CST 2015


Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
---
 dlls/ole32/filemoniker.c   |  4 ++--
 dlls/ole32/tests/moniker.c | 38 ++++++++++++++++++++++++++++++++++++--
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/dlls/ole32/filemoniker.c b/dlls/ole32/filemoniker.c
index 9586be9..2994228 100644
--- a/dlls/ole32/filemoniker.c
+++ b/dlls/ole32/filemoniker.c
@@ -1422,11 +1422,11 @@ HRESULT WINAPI CreateFileMoniker(LPCOLESTR lpszPathName, IMoniker **ppmk)
     if (!ppmk)
         return E_POINTER;
 
+    *ppmk = NULL;
+
     if(!lpszPathName)
         return MK_E_SYNTAX;
 
-    *ppmk=NULL;
-
     newFileMoniker = HeapAlloc(GetProcessHeap(), 0, sizeof(FileMonikerImpl));
 
     if (!newFileMoniker)
diff --git a/dlls/ole32/tests/moniker.c b/dlls/ole32/tests/moniker.c
index dca85ac..bc21af2 100644
--- a/dlls/ole32/tests/moniker.c
+++ b/dlls/ole32/tests/moniker.c
@@ -55,6 +55,7 @@ do { \
 static char const * const *expected_method_list;
 static const WCHAR wszFileName1[] = {'c',':','\\','w','i','n','d','o','w','s','\\','t','e','s','t','1','.','d','o','c',0};
 static const WCHAR wszFileName2[] = {'c',':','\\','w','i','n','d','o','w','s','\\','t','e','s','t','2','.','d','o','c',0};
+static HRESULT WINAPI (*pDllGetClassObject)(REFCLSID,REFIID,void**);
 
 static const CLSID CLSID_TestMoniker =
 { /* b306bfbc-496e-4f53-b93e-2ff9c83223d7 */
@@ -64,6 +65,8 @@ static const CLSID CLSID_TestMoniker =
     {0xb9, 0x3e, 0x2f, 0xf9, 0xc8, 0x32, 0x23, 0xd7}
 };
 
+DEFINE_OLEGUID(CLSID_FileMoniker, 0x303, 0, 0);
+
 static LONG cLocks;
 
 static void LockModule(void)
@@ -1545,8 +1548,11 @@ static void test_file_monikers(void)
          */ 
         {0x20ac, 0x2020, 0x100, 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, 0x107, 0x108, 0x109, 0x10a, 0x10b, 0x10c,  0},
         };
-
-    int i; 
+    static const WCHAR emptyW[] = { 0 };
+    IMoniker *moniker, *moniker2;
+    IClassFactory *factory;
+    HRESULT hr;
+    int i;
 
     trace("ACP is %u\n", GetACP());
 
@@ -1569,6 +1575,34 @@ static void test_file_monikers(void)
             test_file_moniker(wszFile[i]);
         }
     }
+
+if (0) /* crashes on native */
+    hr = CreateFileMoniker(NULL, NULL);
+
+    moniker = (void*)0xdeadbeef;
+    hr = CreateFileMoniker(NULL, &moniker);
+    ok(hr == MK_E_SYNTAX, "got 0x%08x\n", hr);
+    ok(moniker == NULL, "got %p\n", moniker);
+
+    pDllGetClassObject = (void*)GetProcAddress(GetModuleHandleA("ole32"), "DllGetClassObject");
+
+    /* empty name */
+    moniker = NULL;
+    hr = CreateFileMoniker(emptyW, &moniker);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+
+    hr = pDllGetClassObject(&CLSID_FileMoniker, &IID_IClassFactory, (void**)&factory);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+
+    hr = IClassFactory_CreateInstance(factory, NULL, &IID_IMoniker, (void**)&moniker2);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+    IClassFactory_Release(factory);
+
+    hr = IMoniker_IsEqual(moniker, moniker2);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+
+    IMoniker_Release(moniker2);
+    IMoniker_Release(moniker);
 }
 
 static void test_item_moniker(void)
-- 
2.6.4




More information about the wine-patches mailing list