oleaut32: Fix crash in LoadTypeLib if typelib name is not specified.
authorPiotr Caban <piotr@codeweavers.com>
Wed, 17 Feb 2010 12:01:33 +0000 (13:01 +0100)
committerAlexandre Julliard <julliard@winehq.org>
Wed, 17 Feb 2010 15:31:01 +0000 (16:31 +0100)
dlls/oleaut32/tests/typelib.c
dlls/oleaut32/typelib.c

index 936c497e55f5756d67fe98d9692544406afd8d01..843af087afaa900183b53b757058dc87d9fb399e 100644 (file)
@@ -968,6 +968,33 @@ if(use_midl_tlb) {
     return;
 }
 
+static void test_CreateTypeLib(void) {
+    char filename[MAX_PATH];
+    WCHAR filenameW[MAX_PATH];
+    ICreateTypeLib2 *createtl;
+    ITypeLib *tl;
+    HRESULT hres;
+
+    trace("CreateTypeLib tests\n");
+
+    GetTempFileNameA(".", "tlb", 0, filename);
+    MultiByteToWideChar(CP_ACP, 0, filename, -1, filenameW, MAX_PATH);
+
+    hres = CreateTypeLib2(SYS_WIN32, filenameW, &createtl);
+    ok(hres == S_OK, "got %08x\n", hres);
+
+    hres = ICreateTypeLib2_SaveAllChanges(createtl);
+    ok(hres == S_OK, "got %08x\n", hres);
+    ICreateTypeLib2_Release(createtl);
+
+    hres = LoadTypeLib(filenameW,  &tl);
+    ok(hres == S_OK, "got %08x\n", hres);
+
+    ITypeLib_Release(tl);
+
+    DeleteFileA(filename);
+}
+
 #if 0       /* use this to generate more tests */
 
 #define OLE_CHECK(x) { HRESULT hr = x; if (FAILED(hr)) { printf(#x "failed - %x\n", hr); return; } }
@@ -1480,6 +1507,7 @@ START_TEST(typelib)
     test_TypeInfo();
     test_QueryPathOfRegTypeLib();
     test_inheritance();
+    test_CreateTypeLib();
 
     if ((filename = create_test_typelib()))
     {
index 2ad54128f1c182ed3a9f257a401037c9211894e5..445eac5c51e5fcec6459d46bc58c96328decefc1 100644 (file)
@@ -552,7 +552,9 @@ HRESULT WINAPI RegisterTypeLib(
         LPOLESTR doc;
 
         /* Set the human-readable name of the typelib */
-        if (SUCCEEDED(ITypeLib_GetDocumentation(ptlib, -1, NULL, &doc, NULL, NULL)))
+        if (FAILED(ITypeLib_GetDocumentation(ptlib, -1, NULL, &doc, NULL, NULL)))
+            res = E_FAIL;
+        else if (doc)
         {
             if (RegSetValueExW(key, NULL, 0, REG_SZ,
                 (BYTE *)doc, (lstrlenW(doc)+1) * sizeof(OLECHAR)) != ERROR_SUCCESS)
@@ -560,8 +562,6 @@ HRESULT WINAPI RegisterTypeLib(
 
             SysFreeString(doc);
         }
-        else
-            res = E_FAIL;
 
         /* Make up the name of the typelib path subkey */
         if (!get_lcid_subkey( attr->lcid, attr->syskind, tmp )) res = E_FAIL;