From 160b9149a1b7b30c65833194653bb390924c887e Mon Sep 17 00:00:00 2001 From: Juan Lang Date: Sat, 3 Sep 2005 09:36:55 +0000 Subject: [PATCH] Improve CryptAlgIdToOID/CryptOIDToAlgId tests, and prevent a crash in CryptOIDToAlgId. --- dlls/crypt32/main.c | 9 ++++++--- dlls/crypt32/tests/main.c | 33 +++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/dlls/crypt32/main.c b/dlls/crypt32/main.c index 87bf9b1581a..b41fb4aaebc 100644 --- a/dlls/crypt32/main.c +++ b/dlls/crypt32/main.c @@ -294,10 +294,13 @@ DWORD WINAPI CertOIDToAlgId(LPCSTR pszObjId) { int i; - for (i = 0; i < sizeof(oidToAlgID) / sizeof(oidToAlgID[0]); i++) + if (pszObjId) { - if (!strcmp(pszObjId, oidToAlgID[i].oid)) - return oidToAlgID[i].algID; + for (i = 0; i < sizeof(oidToAlgID) / sizeof(oidToAlgID[0]); i++) + { + if (!strcmp(pszObjId, oidToAlgID[i].oid)) + return oidToAlgID[i].algID; + } } return 0; } diff --git a/dlls/crypt32/tests/main.c b/dlls/crypt32/tests/main.c index 589238f124f..c45d87c4b66 100644 --- a/dlls/crypt32/tests/main.c +++ b/dlls/crypt32/tests/main.c @@ -87,12 +87,21 @@ static const struct OIDToAlgID algIDToOID[] = { static void testOIDToAlgID(void) { int i; + DWORD alg; + + /* Test with a bogus one */ + SetLastError(0xdeadbeef); + alg = CertOIDToAlgId("1.2.3"); + ok(!alg && GetLastError() == 0xdeadbeef, + "Didn't expect last error (%08lx) to be set\n", GetLastError()); for (i = 0; i < sizeof(oidToAlgID) / sizeof(oidToAlgID[0]); i++) { - DWORD alg = CertOIDToAlgId(oidToAlgID[i].oid); - - ok(alg == oidToAlgID[i].algID, + alg = CertOIDToAlgId(oidToAlgID[i].oid); + /* Not all Windows installations support all these, so make sure it's + * at least not the wrong one. + */ + ok(alg == 0 || alg == oidToAlgID[i].algID, "Expected %ld, got %ld\n", oidToAlgID[i].algID, alg); } } @@ -100,16 +109,20 @@ static void testOIDToAlgID(void) static void testAlgIDToOID(void) { int i; + LPCSTR oid; + /* Test with a bogus one */ + SetLastError(0xdeadbeef); + oid = CertAlgIdToOID(ALG_CLASS_SIGNATURE | ALG_TYPE_ANY | 80); + ok(!oid && GetLastError() == 0xdeadbeef, + "Didn't expect last error (%08lx) to be set\n", GetLastError()); for (i = 0; i < sizeof(algIDToOID) / sizeof(algIDToOID[0]); i++) { - LPCSTR oid = CertAlgIdToOID(algIDToOID[i].algID); - - if ((!oid || !algIDToOID[i].oid) && oid != algIDToOID[i].oid && - algIDToOID[i].algID) - printf("Expected %s, got %s\n", algIDToOID[i].oid, oid); - else if (oid && algIDToOID[i].oid && strcmp(oid, algIDToOID[i].oid)) - printf("Expected %s, got %s\n", algIDToOID[i].oid, oid); + oid = CertAlgIdToOID(algIDToOID[i].algID); + /* Allow failure, not every version of Windows supports every algo */ + if (oid) + ok(!strcmp(oid, algIDToOID[i].oid), + "Expected %s, got %s\n", algIDToOID[i].oid, oid); } }