>From 036d6d7f7b781b1c652af7afec6f64eef75c5054 Mon Sep 17 00:00:00 2001 From: Paul Vriens Date: Wed, 27 May 2009 11:10:07 +0200 Subject: [PATCH] Prevent crash when ConvertSidToStringSidA is not available --- dlls/msi/tests/install.c | 20 +++++++++----------- dlls/msi/tests/package.c | 37 +++++++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/dlls/msi/tests/install.c b/dlls/msi/tests/install.c index 2e03bf4..a554e34 100644 --- a/dlls/msi/tests/install.c +++ b/dlls/msi/tests/install.c @@ -40,6 +40,8 @@ static UINT (WINAPI *pMsiSourceListEnumSourcesA) static UINT (WINAPI *pMsiSourceListGetInfoA) (LPCSTR, LPCSTR, MSIINSTALLCONTEXT, DWORD, LPCSTR, LPSTR, LPDWORD); +static BOOL (WINAPI *pConvertSidToStringSidA)(PSID, LPSTR*); + static HMODULE hsrclient = 0; static BOOL (WINAPI *pSRRemoveRestorePoint)(DWORD); static BOOL (WINAPI *pSRSetRestorePointA)(RESTOREPOINTINFOA*, STATEMGRSTATUS*); @@ -1316,6 +1318,7 @@ static int CDECL fci_delete(char *pszFile, int *err, void *pv) static void init_functionpointers(void) { HMODULE hmsi = GetModuleHandleA("msi.dll"); + HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll"); #define GET_PROC(mod, func) \ p ## func = (void*)GetProcAddress(mod, #func); \ @@ -1326,6 +1329,8 @@ static void init_functionpointers(void) GET_PROC(hmsi, MsiSourceListEnumSourcesA); GET_PROC(hmsi, MsiSourceListGetInfoA); + GET_PROC(hadvapi32, ConvertSidToStringSidA); + hsrclient = LoadLibraryA("srclient.dll"); GET_PROC(hsrclient, SRRemoveRestorePoint); GET_PROC(hsrclient, SRSetRestorePointA); @@ -1352,21 +1357,14 @@ static LPSTR get_user_sid(LPSTR *usersid) BYTE buf[1024]; DWORD size; PTOKEN_USER user; - static HMODULE hadvapi32 = NULL; - static BOOL (WINAPI *pConvertSidToStringSidA)(PSID, LPSTR*); - *usersid = NULL; - if (!hadvapi32) + if (!pConvertSidToStringSidA) { - hadvapi32 = GetModuleHandleA("advapi32.dll"); - pConvertSidToStringSidA = (void *)GetProcAddress(hadvapi32, "ConvertSidToStringSidA"); - if (!pConvertSidToStringSidA) - { - win_skip("ConvertSidToStringSidA is not available\n"); - return NULL; - } + win_skip("ConvertSidToStringSidA is not available\n"); + return NULL; } + *usersid = NULL; OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token); size = sizeof(buf); GetTokenInformation(token, TokenUser, buf, size, &size); diff --git a/dlls/msi/tests/package.c b/dlls/msi/tests/package.c index 21795d5..f986125 100644 --- a/dlls/msi/tests/package.c +++ b/dlls/msi/tests/package.c @@ -34,27 +34,38 @@ char CURR_DIR[MAX_PATH]; static UINT (WINAPI *pMsiApplyMultiplePatchesA)(LPCSTR, LPCSTR, LPCSTR); +static BOOL (WINAPI *pConvertSidToStringSidA)(PSID, LPSTR*); + +static void init_functionpointers(void) +{ + HMODULE hmsi = GetModuleHandleA("msi.dll"); + HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll"); + +#define GET_PROC(mod, func) \ + p ## func = (void*)GetProcAddress(mod, #func); + + GET_PROC(hmsi, MsiApplyMultiplePatchesA); + + GET_PROC(hadvapi32, ConvertSidToStringSidA); + +#undef GET_PROC +} + + static LPSTR get_user_sid(LPSTR *usersid) { HANDLE token; BYTE buf[1024]; DWORD size; PTOKEN_USER user; - static HMODULE hadvapi32 = NULL; - static BOOL (WINAPI *pConvertSidToStringSidA)(PSID, LPSTR*); - *usersid = NULL; - if (!hadvapi32) + if (!pConvertSidToStringSidA) { - hadvapi32 = GetModuleHandleA("advapi32.dll"); - pConvertSidToStringSidA = (void *)GetProcAddress(hadvapi32, "ConvertSidToStringSidA"); - if (!pConvertSidToStringSidA) - { - win_skip("ConvertSidToStringSidA is not available\n"); - return NULL; - } + win_skip("ConvertSidToStringSidA is not available\n"); + return NULL; } + *usersid = NULL; OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token); size = sizeof(buf); GetTokenInformation(token, TokenUser, buf, size, &size); @@ -11622,9 +11633,7 @@ static void test_MsiApplyPatch(void) START_TEST(package) { - HMODULE hmsi = GetModuleHandleA("msi.dll"); - - pMsiApplyMultiplePatchesA = (void *)GetProcAddress(hmsi, "MsiApplyMultiplePatchesA"); + init_functionpointers(); GetCurrentDirectoryA(MAX_PATH, CURR_DIR); -- 1.6.0.6