https://git.reactos.org/?p=reactos.git;a=commitdiff;h=f9395e92afe042726d666…
commit f9395e92afe042726d66630da93245e4da623829
Author: Mark Jansen <mark.jansen(a)reactos.org>
AuthorDate: Sun Jan 21 11:18:59 2018 +0100
Commit: Mark Jansen <mark.jansen(a)reactos.org>
CommitDate: Sun Jan 21 21:13:08 2018 +0100
[APPHELP][APPHELP_APITEST] Fix SdbGetAppPatchDir prototype
---
dll/appcompat/apphelp/apphelp.h | 2 +-
dll/appcompat/apphelp/hsdb.c | 18 ++--
dll/appcompat/apphelp/shimeng.c | 2 +-
modules/rostests/apitests/apphelp/apphelp.c | 102 ++++++++++++++++-----
.../rostests/apitests/appshim/appshim_apitest.h | 2 +-
modules/rostests/apitests/appshim/versionlie.c | 2 +-
6 files changed, 91 insertions(+), 37 deletions(-)
diff --git a/dll/appcompat/apphelp/apphelp.h b/dll/appcompat/apphelp/apphelp.h
index 0107d3e7ce..f2af2b0afc 100644
--- a/dll/appcompat/apphelp/apphelp.h
+++ b/dll/appcompat/apphelp/apphelp.h
@@ -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);
diff --git a/dll/appcompat/apphelp/hsdb.c b/dll/appcompat/apphelp/hsdb.c
index ea61555539..903968d0d6 100644
--- a/dll/appcompat/apphelp/hsdb.c
+++ b/dll/appcompat/apphelp/hsdb.c
@@ -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(a)reactos.org)
+ * Copyright 2015-2018 Mark Jansen (mark.jansen(a)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;
}
}
diff --git a/dll/appcompat/apphelp/shimeng.c b/dll/appcompat/apphelp/shimeng.c
index 20f125a456..667af704ed 100644
--- a/dll/appcompat/apphelp/shimeng.c
+++ b/dll/appcompat/apphelp/shimeng.c
@@ -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;
diff --git a/modules/rostests/apitests/apphelp/apphelp.c
b/modules/rostests/apitests/apphelp/apphelp.c
index 3fb27b21ac..4a300e3e5a 100644
--- a/modules/rostests/apitests/apphelp/apphelp.c
+++ b/modules/rostests/apitests/apphelp/apphelp.c
@@ -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();
}
diff --git a/modules/rostests/apitests/appshim/appshim_apitest.h
b/modules/rostests/apitests/appshim/appshim_apitest.h
index 1f3a0f6bb2..13f08f6b45 100644
--- a/modules/rostests/apitests/appshim/appshim_apitest.h
+++ b/modules/rostests/apitests/appshim/appshim_apitest.h
@@ -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);
diff --git a/modules/rostests/apitests/appshim/versionlie.c
b/modules/rostests/apitests/appshim/versionlie.c
index 5322b8a03e..b36bfe5cf7 100644
--- a/modules/rostests/apitests/appshim/versionlie.c
+++ b/modules/rostests/apitests/appshim/versionlie.c
@@ -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))