[APPHELP][APPHELP_APITEST] Fix SdbGetAppPatchDir prototype
authorMark Jansen <mark.jansen@reactos.org>
Sun, 21 Jan 2018 10:18:59 +0000 (11:18 +0100)
committerMark Jansen <mark.jansen@reactos.org>
Sun, 21 Jan 2018 20:13:08 +0000 (21:13 +0100)
dll/appcompat/apphelp/apphelp.h
dll/appcompat/apphelp/hsdb.c
dll/appcompat/apphelp/shimeng.c
modules/rostests/apitests/apphelp/apphelp.c
modules/rostests/apitests/appshim/appshim_apitest.h
modules/rostests/apitests/appshim/versionlie.c

index 0107d3e..f2af2b0 100644 (file)
@@ -87,7 +87,7 @@ LPCWSTR WINAPI SdbTagToString(TAG tag);
 PDB WINAPI SdbOpenDatabase(LPCWSTR path, PATH_TYPE type);
 void WINAPI SdbCloseDatabase(PDB);
 BOOL WINAPI SdbIsNullGUID(CONST GUID *Guid);
-BOOL WINAPI SdbGetAppPatchDir(HSDB db, LPWSTR path, DWORD size);
+HRESULT WINAPI SdbGetAppPatchDir(HSDB db, LPWSTR path, DWORD size);
 LPWSTR WINAPI SdbGetStringTagPtr(PDB pdb, TAGID tagid);
 TAGID WINAPI SdbFindFirstNamedTag(PDB pdb, TAGID root, TAGID find, TAGID nametag, LPCWSTR find_name);
 
index ea61555..903968d 100644 (file)
@@ -4,7 +4,7 @@
  * PURPOSE:     Shim matching / data (un)packing
  * COPYRIGHT:   Copyright 2011 André Hentschel
  *              Copyright 2013 Mislav Blaževic
- *              Copyright 2015-2017 Mark Jansen (mark.jansen@reactos.org)
+ *              Copyright 2015-2018 Mark Jansen (mark.jansen@reactos.org)
  */
 
 #define WIN32_NO_STATUS
@@ -563,11 +563,11 @@ Cleanup:
 /**
  * Retrieves AppPatch directory.
  *
- * @param [in]  pdb      Handle to the shim database.
+ * @param [in]  pdb     Handle to the shim database.
  * @param [out] path    Pointer to memory in which path shall be written.
  * @param [in]  size    Size of the buffer in characters.
  */
-BOOL WINAPI SdbGetAppPatchDir(HSDB hsdb, LPWSTR path, DWORD size)
+HRESULT WINAPI SdbGetAppPatchDir(HSDB hsdb, LPWSTR path, DWORD size)
 {
     static WCHAR* default_dir = NULL;
     static CONST WCHAR szAppPatch[] = {'\\','A','p','p','P','a','t','c','h',0};
@@ -579,6 +579,7 @@ BOOL WINAPI SdbGetAppPatchDir(HSDB hsdb, LPWSTR path, DWORD size)
     if (!default_dir)
     {
         WCHAR* tmp;
+        HRESULT hr = E_FAIL;
         UINT len = GetSystemWindowsDirectoryW(NULL, 0) + SdbpStrlen(szAppPatch);
         tmp = SdbAlloc((len + 1)* sizeof(WCHAR));
         if (tmp)
@@ -586,7 +587,8 @@ BOOL WINAPI SdbGetAppPatchDir(HSDB hsdb, LPWSTR path, DWORD size)
             UINT r = GetSystemWindowsDirectoryW(tmp, len+1);
             if (r && r < len)
             {
-                if (SUCCEEDED(StringCchCatW(tmp, len+1, szAppPatch)))
+                hr = StringCchCatW(tmp, len+1, szAppPatch);
+                if (SUCCEEDED(hr))
                 {
                     if (InterlockedCompareExchangePointer((void**)&default_dir, tmp, NULL) == NULL)
                         tmp = NULL;
@@ -597,19 +599,19 @@ BOOL WINAPI SdbGetAppPatchDir(HSDB hsdb, LPWSTR path, DWORD size)
         }
         if (!default_dir)
         {
-            SHIM_ERR("Unable to obtain default AppPatch directory\n");
-            return FALSE;
+            SHIM_ERR("Unable to obtain default AppPatch directory (0x%x)\n", hr);
+            return hr;
         }
     }
 
     if (!hsdb)
     {
-        return SUCCEEDED(StringCchCopyW(path, size, default_dir));
+        return StringCchCopyW(path, size, default_dir);
     }
     else
     {
         SHIM_ERR("Unimplemented for hsdb != NULL\n");
-        return FALSE;
+        return E_NOTIMPL;
     }
 }
 
index 20f125a..667af70 100644 (file)
@@ -1040,7 +1040,7 @@ VOID SeiInit(PUNICODE_STRING ProcessImage, HSDB hsdb, SDBQUERYRESULT* pQuery)
                 continue;
             }
 
-            if (!SdbGetAppPatchDir(NULL, FullNameBuffer, ARRAYSIZE(FullNameBuffer)))
+            if (!SUCCEEDED(SdbGetAppPatchDir(NULL, FullNameBuffer, ARRAYSIZE(FullNameBuffer))))
             {
                 SHIMENG_WARN("Failed to get the AppPatch dir\n");
                 continue;
index 3fb27b2..4a300e3 100644 (file)
@@ -87,12 +87,13 @@ typedef struct tagATTRINFO {
 
 static HMODULE hdll;
 static BOOL (WINAPI *pApphelpCheckShellObject)(REFCLSID, BOOL, ULONGLONG *);
-static LPCWSTR (WINAPI *pSdbTagToString)(TAG);
-static BOOL (WINAPI *pSdbGUIDToString)(CONST GUID *, PCWSTR, SIZE_T);
-static BOOL (WINAPI *pSdbIsNullGUID)(CONST GUID *);
-static BOOL (WINAPI *pSdbGetStandardDatabaseGUID)(DWORD, GUID*);
-static BOOL (WINAPI *pSdbGetFileAttributes)(LPCWSTR, PATTRINFO *, LPDWORD);
-static BOOL (WINAPI *pSdbFreeFileAttributes)(PATTRINFO);
+static LPCWSTR (WINAPI *pSdbTagToString)(TAG tag);
+static BOOL (WINAPI *pSdbGUIDToString)(REFGUID Guid, PWSTR GuidString, SIZE_T Length);
+static BOOL (WINAPI *pSdbIsNullGUID)(REFGUID Guid);
+static BOOL (WINAPI *pSdbGetStandardDatabaseGUID)(DWORD Flags, GUID* Guid);
+static BOOL (WINAPI *pSdbGetFileAttributes)(LPCWSTR wszPath, PATTRINFO *ppAttrInfo, LPDWORD pdwAttrCount);
+static BOOL (WINAPI *pSdbFreeFileAttributes)(PATTRINFO AttrInfo);
+static HRESULT (WINAPI* pSdbGetAppPatchDir)(PVOID hsdb, LPWSTR path, DWORD size);
 
 /* 'Known' database guids */
 DEFINE_GUID(GUID_DATABASE_MSI,0xd8ff6d16,0x6a3a,0x468a,0x8b,0x44,0x01,0x71,0x4d,0xdc,0x49,0xea);
@@ -869,34 +870,85 @@ static void test_ApplicationAttributes(void)
     DeleteFileA("testxx.exe");
 }
 
-START_TEST(apphelp)
+/* Showing that SdbGetAppPatchDir returns HRESULT */
+static void test_SdbGetAppPatchDir(void)
 {
-    g_WinVersion = get_host_winver();
-    trace("Detected version: 0x%x\n", g_WinVersion);
-    silence_debug_output();
+    WCHAR Buffer[MAX_PATH];
+    HRESULT hr, expect_hr;
+    int n;
+
+
+    _SEH2_TRY
+    {
+        hr = pSdbGetAppPatchDir(NULL, NULL, 0);
+        ok_hex(hr, S_FALSE);
+    }
+    _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+    {
+        /* Some versions accept it, some don't */
+        trace("SdbGetAppPatchDir did not handle a NULL pointer very gracefully.\n");
+    }
+    _SEH2_END;
+
+
+
+    memset(Buffer, 0xbb, sizeof(Buffer));
+    hr = pSdbGetAppPatchDir(NULL, Buffer, 0);
+    if (g_WinVersion < WINVER_WIN7)
+        expect_hr = HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
+    else if (g_WinVersion < WINVER_WIN10)
+        expect_hr = S_OK;
+    else
+        expect_hr = S_FALSE;
+    ok_hex(hr, expect_hr);
+
+    if (g_WinVersion < WINVER_WIN7)
+        expect_hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
+    else if (g_WinVersion < WINVER_WIN10)
+        expect_hr = S_OK;
+    else
+        expect_hr = TRUE;
 
+    memset(Buffer, 0xbb, sizeof(Buffer));
+    hr = pSdbGetAppPatchDir(NULL, Buffer, 1);
+    ok_hex(hr, expect_hr);
+
+
+    for (n = 2; n < _countof(Buffer) - 1; ++n)
+    {
+        memset(Buffer, 0xbb, sizeof(Buffer));
+        hr = pSdbGetAppPatchDir(NULL, Buffer, n);
+        ok(Buffer[n] == 0xbbbb, "Expected SdbGetAppPatchDir to leave WCHAR at %d untouched, was: %d\n",
+           n, Buffer[n]);
+        ok(hr == S_OK || hr == expect_hr, "Expected S_OK or 0x%x, was: 0x%x (at %d)\n", expect_hr, hr, n);
+    }
+}
+START_TEST(apphelp)
+{
     //SetEnvironmentVariable("SHIM_DEBUG_LEVEL", "4");
     //SetEnvironmentVariable("DEBUGCHANNEL", "+apphelp");
-    hdll = LoadLibraryA("apphelp.dll");
+    silence_debug_output();
 
-    pApphelpCheckShellObject = (void *) GetProcAddress(hdll, "ApphelpCheckShellObject");
-    pSdbTagToString = (void *) GetProcAddress(hdll, "SdbTagToString");
-    pSdbGUIDToString = (void *) GetProcAddress(hdll, "SdbGUIDToString");
-    pSdbIsNullGUID = (void *) GetProcAddress(hdll, "SdbIsNullGUID");
-    pSdbGetStandardDatabaseGUID = (void *) GetProcAddress(hdll, "SdbGetStandardDatabaseGUID");
-    pSdbGetFileAttributes = (void *) GetProcAddress(hdll, "SdbGetFileAttributes");
-    pSdbFreeFileAttributes = (void *) GetProcAddress(hdll, "SdbFreeFileAttributes");
+    hdll = LoadLibraryA("apphelp.dll");
+    g_WinVersion = get_module_version(hdll);
+    trace("Detected apphelp.dll version: 0x%x\n", g_WinVersion);
+
+#define RESOLVE(fnc)    do { p##fnc = (void *) GetProcAddress(hdll, #fnc); ok(!!p##fnc, #fnc " not found.\n"); } while (0)
+    RESOLVE(ApphelpCheckShellObject);
+    RESOLVE(SdbTagToString);
+    RESOLVE(SdbGUIDToString);
+    RESOLVE(SdbIsNullGUID);
+    RESOLVE(SdbGetStandardDatabaseGUID);
+    RESOLVE(SdbGetFileAttributes);
+    RESOLVE(SdbFreeFileAttributes);
+    RESOLVE(SdbGetAppPatchDir);
+#undef RESOLVE
 
     test_ApphelpCheckShellObject();
     test_GuidFunctions();
     test_ApplicationAttributes();
     test_SdbTagToString();
-#ifdef __REACTOS__
-    if (g_WinVersion < WINVER_WIN7)
-    {
-        g_WinVersion = WINVER_WIN7;
-        trace("Using version 0x%x for SdbTagToString tests\n", g_WinVersion);
-    }
-#endif
     test_SdbTagToStringAllTags();
+    if (pSdbGetAppPatchDir)
+        test_SdbGetAppPatchDir();
 }
index 1f3a0f6..13f08f6 100644 (file)
@@ -14,7 +14,7 @@ typedef struct tagHOOKAPI {
     PVOID Unk2;
 } HOOKAPI, *PHOOKAPI;
 
-typedef BOOL (WINAPI* tSDBGETAPPPATCHDIR)(PVOID hsdb, LPWSTR path, DWORD size);
+typedef HRESULT (WINAPI* tSDBGETAPPPATCHDIR)(PVOID hsdb, LPWSTR path, DWORD size);
 typedef PHOOKAPI (WINAPI* tGETHOOKAPIS)(LPCSTR szCommandLine, LPCWSTR wszShimName, PDWORD pdwHookCount);
 
 
index 5322b8a..b36bfe5 100644 (file)
@@ -309,7 +309,7 @@ BOOL LoadShimDLL(PCWSTR ShimDll, HMODULE* module, tGETHOOKAPIS* ppGetHookAPIs)
         }
     }
 
-    if (!pSdbGetAppPatchDir || !pSdbGetAppPatchDir(NULL, buf, MAX_PATH))
+    if (!pSdbGetAppPatchDir || !SUCCEEDED(pSdbGetAppPatchDir(NULL, buf, MAX_PATH)))
     {
         skip("Unable to retrieve AppPatch dir, building manually\n");
         if (!GetSystemWindowsDirectoryW(buf, MAX_PATH))