From 0a866d0e4599b91cef247da883b0a93ccf7c0681 Mon Sep 17 00:00:00 2001 From: Michael Stefaniuc Date: Fri, 29 Jan 2010 01:39:26 +0100 Subject: [PATCH] crypt32: Avoid using HIWORD() on a string pointer. The stray IS_INTRESOURCE() is applied to a true resource. The other strings are OIDs and not resources. --- dlls/crypt32/chain.c | 2 +- dlls/crypt32/crypt32_private.h | 4 ++++ dlls/crypt32/decode.c | 2 +- dlls/crypt32/encode.c | 2 +- dlls/crypt32/object.c | 2 +- dlls/crypt32/oid.c | 12 ++++++------ dlls/crypt32/store.c | 2 +- dlls/crypt32/tests/chain.c | 22 ++++++++++++---------- 8 files changed, 27 insertions(+), 21 deletions(-) diff --git a/dlls/crypt32/chain.c b/dlls/crypt32/chain.c index b2160f3c776..6cdd103e666 100644 --- a/dlls/crypt32/chain.c +++ b/dlls/crypt32/chain.c @@ -3380,7 +3380,7 @@ BOOL WINAPI CertVerifyCertificateChainPolicy(LPCSTR szPolicyOID, TRACE("(%s, %p, %p, %p)\n", debugstr_a(szPolicyOID), pChainContext, pPolicyPara, pPolicyStatus); - if (!HIWORD(szPolicyOID)) + if (IS_INTOID(szPolicyOID)) { switch (LOWORD(szPolicyOID)) { diff --git a/dlls/crypt32/crypt32_private.h b/dlls/crypt32/crypt32_private.h index cbdf5116f9c..8385bf50713 100644 --- a/dlls/crypt32/crypt32_private.h +++ b/dlls/crypt32/crypt32_private.h @@ -405,4 +405,8 @@ void ContextList_Free(struct ContextList *list); #define ALIGN_DWORD_PTR(x) (((x) + sizeof(DWORD_PTR) - 1) & ~(sizeof(DWORD_PTR) - 1)) #define POINTER_ALIGN_DWORD_PTR(p) ((LPVOID)ALIGN_DWORD_PTR((DWORD_PTR)(p))) +/* Check if the OID is a small int + */ +#define IS_INTOID(x) (((ULONG_PTR)(x) >> 16) == 0) + #endif diff --git a/dlls/crypt32/decode.c b/dlls/crypt32/decode.c index 1fd23837395..fb3d36e8124 100644 --- a/dlls/crypt32/decode.c +++ b/dlls/crypt32/decode.c @@ -5578,7 +5578,7 @@ static CryptDecodeObjectExFunc CRYPT_GetBuiltinDecoder(DWORD dwCertEncodingType, SetLastError(ERROR_FILE_NOT_FOUND); return NULL; } - if (!HIWORD(lpszStructType)) + if (IS_INTOID(lpszStructType)) { switch (LOWORD(lpszStructType)) { diff --git a/dlls/crypt32/encode.c b/dlls/crypt32/encode.c index b7bbc83600c..c58b0e638e9 100644 --- a/dlls/crypt32/encode.c +++ b/dlls/crypt32/encode.c @@ -4305,7 +4305,7 @@ static CryptEncodeObjectExFunc CRYPT_GetBuiltinEncoder(DWORD dwCertEncodingType, return NULL; } - if (!HIWORD(lpszStructType)) + if (IS_INTOID(lpszStructType)) { switch (LOWORD(lpszStructType)) { diff --git a/dlls/crypt32/object.c b/dlls/crypt32/object.c index 3d18c505fb4..b3f82936172 100644 --- a/dlls/crypt32/object.c +++ b/dlls/crypt32/object.c @@ -2525,7 +2525,7 @@ static CryptFormatObjectFunc CRYPT_GetBuiltinFormatFunction(DWORD encodingType, SetLastError(ERROR_FILE_NOT_FOUND); return NULL; } - if (!HIWORD(lpszStructType)) + if (IS_INTOID(lpszStructType)) { switch (LOWORD(lpszStructType)) { diff --git a/dlls/crypt32/oid.c b/dlls/crypt32/oid.c index 68a48520dac..ea30d9ccd45 100644 --- a/dlls/crypt32/oid.c +++ b/dlls/crypt32/oid.c @@ -170,7 +170,7 @@ static char *CRYPT_GetKeyName(DWORD dwEncodingType, LPCSTR pszFuncName, * "EncodingType 2" would be expected if it were a mask. Instead native * stores values in "EncodingType 3". */ - if (!HIWORD(pszOID)) + if (IS_INTOID(pszOID)) { snprintf(numericOID, sizeof(numericOID), "#%d", LOWORD(pszOID)); oid = numericOID; @@ -255,7 +255,7 @@ BOOL WINAPI CryptInstallOIDFunctionAddress(HMODULE hModule, { struct OIDFunction *func; - if (HIWORD(rgFuncEntry[i].pszOID)) + if (!IS_INTOID(rgFuncEntry[i].pszOID)) func = CryptMemAlloc(sizeof(struct OIDFunction) + strlen(rgFuncEntry[i].pszOID) + 1); else @@ -263,7 +263,7 @@ BOOL WINAPI CryptInstallOIDFunctionAddress(HMODULE hModule, if (func) { func->encoding = GET_CERT_ENCODING_TYPE(dwEncodingType); - if (HIWORD(rgFuncEntry[i].pszOID)) + if (!IS_INTOID(rgFuncEntry[i].pszOID)) { LPSTR oid; @@ -402,9 +402,9 @@ BOOL WINAPI CryptGetOIDFunctionAddress(HCRYPTOIDFUNCSET hFuncSet, { if (function->encoding == GET_CERT_ENCODING_TYPE(dwEncodingType)) { - if (HIWORD(pszOID)) + if (!IS_INTOID(pszOID)) { - if (HIWORD(function->entry.pszOID) && + if (!IS_INTOID(function->entry.pszOID) && !strcasecmp(function->entry.pszOID, pszOID)) { *ppvFuncAddr = function->entry.pvFuncAddr; @@ -1398,7 +1398,7 @@ static void init_oid_info(void) for (i = 0; i < sizeof(oidInfoConstructors) / sizeof(oidInfoConstructors[0]); i++) { - if (HIWORD(oidInfoConstructors[i].pwszName)) + if (!IS_INTRESOURCE(oidInfoConstructors[i].pwszName)) { struct OIDInfo *info; diff --git a/dlls/crypt32/store.c b/dlls/crypt32/store.c index 153d3aa71ea..a8923949974 100644 --- a/dlls/crypt32/store.c +++ b/dlls/crypt32/store.c @@ -745,7 +745,7 @@ HCERTSTORE WINAPI CertOpenStore(LPCSTR lpszStoreProvider, TRACE("(%s, %08x, %08lx, %08x, %p)\n", debugstr_a(lpszStoreProvider), dwMsgAndCertEncodingType, hCryptProv, dwFlags, pvPara); - if (!HIWORD(lpszStoreProvider)) + if (IS_INTOID(lpszStoreProvider)) { switch (LOWORD(lpszStoreProvider)) { diff --git a/dlls/crypt32/tests/chain.c b/dlls/crypt32/tests/chain.c index a626b82c4fe..f9ccaed78b1 100644 --- a/dlls/crypt32/tests/chain.c +++ b/dlls/crypt32/tests/chain.c @@ -58,6 +58,8 @@ static VOID (WINAPI *pCertFreeCertificateChain)(PCCERT_CHAIN_CONTEXT); static VOID (WINAPI *pCertFreeCertificateChainEngine)(HCERTCHAINENGINE); static BOOL (WINAPI *pCertVerifyCertificateChainPolicy)(LPCSTR,PCCERT_CHAIN_CONTEXT,PCERT_CHAIN_POLICY_PARA,PCERT_CHAIN_POLICY_STATUS); +#define IS_INTOID(x) (((ULONG_PTR)(x) >> 16) == 0) + static void testCreateCertChainEngine(void) { @@ -3883,19 +3885,19 @@ static void checkChainPolicyStatus(LPCSTR policy, const ChainPolicyCheck *check, if (check->todo & TODO_POLICY) todo_wine ok(ret, "%s[%d]: CertVerifyCertificateChainPolicy failed: %08x\n", - HIWORD(policy) ? policy : num_to_str(LOWORD(policy)), + IS_INTOID(policy) ? num_to_str(LOWORD(policy)) : policy, testIndex, GetLastError()); else { if (!ret && GetLastError() == ERROR_FILE_NOT_FOUND) { skip("%d: missing policy %s, skipping test\n", testIndex, - HIWORD(policy) ? policy : num_to_str(LOWORD(policy))); + IS_INTOID(policy) ? num_to_str(LOWORD(policy)) : policy); pCertFreeCertificateChain(chain); return; } ok(ret, "%s[%d]: CertVerifyCertificateChainPolicy failed: %08x\n", - HIWORD(policy) ? policy : num_to_str(LOWORD(policy)), testIndex, + IS_INTOID(policy) ? num_to_str(LOWORD(policy)) : policy, testIndex, GetLastError()); } if (ret) @@ -3906,7 +3908,7 @@ static void checkChainPolicyStatus(LPCSTR policy, const ChainPolicyCheck *check, (check->brokenStatus && broken(policyStatus.dwError == check->brokenStatus->dwError)), "%s[%d]: expected %08x, got %08x\n", - HIWORD(policy) ? policy : num_to_str(LOWORD(policy)), + IS_INTOID(policy) ? num_to_str(LOWORD(policy)) : policy, testIndex, check->status.dwError, policyStatus.dwError); else ok(policyStatus.dwError == check->status.dwError || @@ -3914,12 +3916,12 @@ static void checkChainPolicyStatus(LPCSTR policy, const ChainPolicyCheck *check, (check->brokenStatus && broken(policyStatus.dwError == check->brokenStatus->dwError)), "%s[%d]: expected %08x, got %08x\n", - HIWORD(policy) ? policy : num_to_str(LOWORD(policy)), + IS_INTOID(policy) ? num_to_str(LOWORD(policy)) : policy, testIndex, check->status.dwError, policyStatus.dwError); if (policyStatus.dwError != check->status.dwError) { skip("%s[%d]: error %08x doesn't match expected %08x, not checking indexes\n", - HIWORD(policy) ? policy : num_to_str(LOWORD(policy)), + IS_INTOID(policy) ? num_to_str(LOWORD(policy)) : policy, testIndex, policyStatus.dwError, check->status.dwError); pCertFreeCertificateChain(chain); return; @@ -3930,7 +3932,7 @@ static void checkChainPolicyStatus(LPCSTR policy, const ChainPolicyCheck *check, (check->brokenStatus && broken(policyStatus.lChainIndex == check->brokenStatus->lChainIndex)), "%s[%d]: expected %d, got %d\n", - HIWORD(policy) ? policy : num_to_str(LOWORD(policy)), + IS_INTOID(policy) ? num_to_str(LOWORD(policy)) : policy, testIndex, check->status.lChainIndex, policyStatus.lChainIndex); else @@ -3938,7 +3940,7 @@ static void checkChainPolicyStatus(LPCSTR policy, const ChainPolicyCheck *check, (check->brokenStatus && broken(policyStatus.lChainIndex == check->brokenStatus->lChainIndex)), "%s[%d]: expected %d, got %d\n", - HIWORD(policy) ? policy : num_to_str(LOWORD(policy)), + IS_INTOID(policy) ? num_to_str(LOWORD(policy)) : policy, testIndex, check->status.lChainIndex, policyStatus.lChainIndex); if (check->todo & TODO_ELEMENTS) @@ -3947,7 +3949,7 @@ static void checkChainPolicyStatus(LPCSTR policy, const ChainPolicyCheck *check, (check->brokenStatus && broken(policyStatus.lElementIndex == check->brokenStatus->lElementIndex)), "%s[%d]: expected %d, got %d\n", - HIWORD(policy) ? policy : num_to_str(LOWORD(policy)), + IS_INTOID(policy) ? num_to_str(LOWORD(policy)) : policy, testIndex, check->status.lElementIndex, policyStatus.lElementIndex); else @@ -3955,7 +3957,7 @@ static void checkChainPolicyStatus(LPCSTR policy, const ChainPolicyCheck *check, (check->brokenStatus && broken(policyStatus.lElementIndex == check->brokenStatus->lElementIndex)), "%s[%d]: expected %d, got %d\n", - HIWORD(policy) ? policy : num_to_str(LOWORD(policy)), + IS_INTOID(policy) ? num_to_str(LOWORD(policy)) : policy, testIndex, check->status.lElementIndex, policyStatus.lElementIndex); }