crypt32/tests: Don't crash on win9x.

This commit is contained in:
Paul Vriens 2008-09-17 23:20:39 +02:00 committed by Alexandre Julliard
parent 9e68badeaf
commit 9b4a5cd065
1 changed files with 97 additions and 59 deletions

View File

@ -102,13 +102,16 @@ static void test_encodeInt(DWORD dwEncoding)
&bufSize); &bufSize);
ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND, ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
"Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
/* check with NULL integer buffer. Windows XP incorrectly returns an if (0)
* NTSTATUS. {
*/ /* check with NULL integer buffer. Windows XP incorrectly returns an
ret = pCryptEncodeObjectEx(dwEncoding, X509_INTEGER, NULL, 0, NULL, NULL, * NTSTATUS (crashes on win9x).
&bufSize); */
ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION, ret = pCryptEncodeObjectEx(dwEncoding, X509_INTEGER, NULL, 0, NULL, NULL,
"Expected STATUS_ACCESS_VIOLATION, got %08x\n", GetLastError()); &bufSize);
ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION,
"Expected STATUS_ACCESS_VIOLATION, got %08x\n", GetLastError());
}
for (i = 0; i < sizeof(ints) / sizeof(ints[0]); i++) for (i = 0; i < sizeof(ints) / sizeof(ints[0]); i++)
{ {
/* encode as normal integer */ /* encode as normal integer */
@ -729,11 +732,14 @@ static void test_encodeName(DWORD dwEncoding)
DWORD size = 0; DWORD size = 0;
BOOL ret; BOOL ret;
/* Test with NULL pvStructInfo */ if (0)
ret = pCryptEncodeObjectEx(dwEncoding, X509_NAME, NULL, {
CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size); /* Test with NULL pvStructInfo (crashes on win9x) */
ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION, ret = pCryptEncodeObjectEx(dwEncoding, X509_NAME, NULL,
"Expected STATUS_ACCESS_VIOLATION, got %08x\n", GetLastError()); CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION,
"Expected STATUS_ACCESS_VIOLATION, got %08x\n", GetLastError());
}
/* Test with empty CERT_NAME_INFO */ /* Test with empty CERT_NAME_INFO */
info.cRDN = 0; info.cRDN = 0;
info.rgRDN = NULL; info.rgRDN = NULL;
@ -746,12 +752,15 @@ static void test_encodeName(DWORD dwEncoding)
"Got unexpected encoding for empty name\n"); "Got unexpected encoding for empty name\n");
LocalFree(buf); LocalFree(buf);
} }
/* Test with bogus CERT_RDN */ if (0)
info.cRDN = 1; {
ret = pCryptEncodeObjectEx(dwEncoding, X509_NAME, &info, /* Test with bogus CERT_RDN (crashes on win9x) */
CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size); info.cRDN = 1;
ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION, ret = pCryptEncodeObjectEx(dwEncoding, X509_NAME, &info,
"Expected STATUS_ACCESS_VIOLATION, got %08x\n", GetLastError()); CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION,
"Expected STATUS_ACCESS_VIOLATION, got %08x\n", GetLastError());
}
/* Test with empty CERT_RDN */ /* Test with empty CERT_RDN */
rdn.cRDNAttr = 0; rdn.cRDNAttr = 0;
rdn.rgRDNAttr = NULL; rdn.rgRDNAttr = NULL;
@ -766,13 +775,16 @@ static void test_encodeName(DWORD dwEncoding)
"Got unexpected encoding for empty RDN array\n"); "Got unexpected encoding for empty RDN array\n");
LocalFree(buf); LocalFree(buf);
} }
/* Test with bogus attr array */ if (0)
rdn.cRDNAttr = 1; {
rdn.rgRDNAttr = NULL; /* Test with bogus attr array (crashes on win9x) */
ret = pCryptEncodeObjectEx(dwEncoding, X509_NAME, &info, rdn.cRDNAttr = 1;
CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size); rdn.rgRDNAttr = NULL;
ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION, ret = pCryptEncodeObjectEx(dwEncoding, X509_NAME, &info,
"Expected STATUS_ACCESS_VIOLATION, got %08x\n", GetLastError()); CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION,
"Expected STATUS_ACCESS_VIOLATION, got %08x\n", GetLastError());
}
/* oddly, a bogus OID is accepted by Windows XP; not testing. /* oddly, a bogus OID is accepted by Windows XP; not testing.
attrs[0].pszObjId = "bogus"; attrs[0].pszObjId = "bogus";
attrs[0].dwValueType = CERT_RDN_PRINTABLE_STRING; attrs[0].dwValueType = CERT_RDN_PRINTABLE_STRING;
@ -870,11 +882,14 @@ static void test_encodeUnicodeName(DWORD dwEncoding)
DWORD size = 0; DWORD size = 0;
BOOL ret; BOOL ret;
/* Test with NULL pvStructInfo */ if (0)
ret = pCryptEncodeObjectEx(dwEncoding, X509_UNICODE_NAME, NULL, {
CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size); /* Test with NULL pvStructInfo (crashes on win9x) */
ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION, ret = pCryptEncodeObjectEx(dwEncoding, X509_UNICODE_NAME, NULL,
"Expected STATUS_ACCESS_VIOLATION, got %08x\n", GetLastError()); CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION,
"Expected STATUS_ACCESS_VIOLATION, got %08x\n", GetLastError());
}
/* Test with empty CERT_NAME_INFO */ /* Test with empty CERT_NAME_INFO */
info.cRDN = 0; info.cRDN = 0;
info.rgRDN = NULL; info.rgRDN = NULL;
@ -1681,10 +1696,14 @@ static void test_encodeUnicodeNameValue(DWORD dwEncoding)
BOOL ret; BOOL ret;
CERT_NAME_VALUE value; CERT_NAME_VALUE value;
ret = pCryptEncodeObjectEx(dwEncoding, X509_UNICODE_NAME_VALUE, NULL, if (0)
CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size); {
ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION, /* Crashes on win9x */
"Expected STATUS_ACCESS_VIOLATION, got %08x\n", GetLastError()); ret = pCryptEncodeObjectEx(dwEncoding, X509_UNICODE_NAME_VALUE, NULL,
CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION,
"Expected STATUS_ACCESS_VIOLATION, got %08x\n", GetLastError());
}
/* Have to have a string of some sort */ /* Have to have a string of some sort */
value.dwValueType = 0; /* aka CERT_RDN_ANY_TYPE */ value.dwValueType = 0; /* aka CERT_RDN_ANY_TYPE */
value.Value.pbData = NULL; value.Value.pbData = NULL;
@ -2804,11 +2823,14 @@ static void test_encodeCertToBeSigned(DWORD dwEncoding)
static char oid_subject_key_identifier[] = szOID_SUBJECT_KEY_IDENTIFIER; static char oid_subject_key_identifier[] = szOID_SUBJECT_KEY_IDENTIFIER;
CERT_EXTENSION ext; CERT_EXTENSION ext;
/* Test with NULL pvStructInfo */ if (0)
ret = pCryptEncodeObjectEx(dwEncoding, X509_CERT_TO_BE_SIGNED, NULL, {
CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size); /* Test with NULL pvStructInfo (crashes on win9x) */
ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION, ret = pCryptEncodeObjectEx(dwEncoding, X509_CERT_TO_BE_SIGNED, NULL,
"Expected STATUS_ACCESS_VIOLATION, got %08x\n", GetLastError()); CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION,
"Expected STATUS_ACCESS_VIOLATION, got %08x\n", GetLastError());
}
/* Test with a V1 cert */ /* Test with a V1 cert */
ret = pCryptEncodeObjectEx(dwEncoding, X509_CERT_TO_BE_SIGNED, &info, ret = pCryptEncodeObjectEx(dwEncoding, X509_CERT_TO_BE_SIGNED, &info,
CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size); CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
@ -2931,10 +2953,14 @@ static void test_decodeCertToBeSigned(DWORD dwEncoding)
CRYPT_DECODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size); CRYPT_DECODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
ok(!ret && GetLastError() == CRYPT_E_ASN1_EOD, ok(!ret && GetLastError() == CRYPT_E_ASN1_EOD,
"Expected CRYPT_E_ASN1_EOD, got %08x\n", GetLastError()); "Expected CRYPT_E_ASN1_EOD, got %08x\n", GetLastError());
ret = pCryptDecodeObjectEx(dwEncoding, X509_CERT_TO_BE_SIGNED, NULL, 1, if (0)
CRYPT_DECODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size); {
ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION, /* Crashes on win9x */
"Expected STATUS_ACCESS_VIOLATION, got %08x\n", GetLastError()); ret = pCryptDecodeObjectEx(dwEncoding, X509_CERT_TO_BE_SIGNED, NULL, 1,
CRYPT_DECODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION,
"Expected STATUS_ACCESS_VIOLATION, got %08x\n", GetLastError());
}
/* The following certs all fail with CRYPT_E_ASN1_CORRUPT, because at a /* The following certs all fail with CRYPT_E_ASN1_CORRUPT, because at a
* minimum a cert must have a non-zero serial number, an issuer, and a * minimum a cert must have a non-zero serial number, an issuer, and a
* subject. * subject.
@ -3606,13 +3632,17 @@ static void test_encodeCRLToBeSigned(DWORD dwEncoding)
ok(!memcmp(buf, v1CRLWithIssuer, size), "Got unexpected value\n"); ok(!memcmp(buf, v1CRLWithIssuer, size), "Got unexpected value\n");
LocalFree(buf); LocalFree(buf);
} }
/* v1 CRL with a name and a NULL entry pointer */ if (0)
info.cCRLEntry = 1; {
ret = pCryptEncodeObjectEx(dwEncoding, X509_CERT_CRL_TO_BE_SIGNED, &info, /* v1 CRL with a name and a NULL entry pointer (crashes on win9x) */
CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size); info.cCRLEntry = 1;
ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION, ret = pCryptEncodeObjectEx(dwEncoding, X509_CERT_CRL_TO_BE_SIGNED, &info,
"Expected STATUS_ACCESS_VIOLATION, got %08x\n", GetLastError()); CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION,
"Expected STATUS_ACCESS_VIOLATION, got %08x\n", GetLastError());
}
/* now set an empty entry */ /* now set an empty entry */
info.cCRLEntry = 1;
info.rgCRLEntry = &entry; info.rgCRLEntry = &entry;
ret = pCryptEncodeObjectEx(dwEncoding, X509_CERT_CRL_TO_BE_SIGNED, &info, ret = pCryptEncodeObjectEx(dwEncoding, X509_CERT_CRL_TO_BE_SIGNED, &info,
CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size); CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
@ -5519,11 +5549,15 @@ static void test_encodePKCSContentInfo(DWORD dwEncoding)
CRYPT_CONTENT_INFO info = { 0 }; CRYPT_CONTENT_INFO info = { 0 };
char oid1[] = "1.2.3"; char oid1[] = "1.2.3";
SetLastError(0xdeadbeef); if (0)
ret = pCryptEncodeObjectEx(dwEncoding, PKCS_CONTENT_INFO, NULL, {
CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size); /* Crashes on win9x */
ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION, SetLastError(0xdeadbeef);
"Expected STATUS_ACCESS_VIOLATION, got %x\n", GetLastError()); ret = pCryptEncodeObjectEx(dwEncoding, PKCS_CONTENT_INFO, NULL,
CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION,
"Expected STATUS_ACCESS_VIOLATION, got %x\n", GetLastError());
}
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
ret = pCryptEncodeObjectEx(dwEncoding, PKCS_CONTENT_INFO, &info, ret = pCryptEncodeObjectEx(dwEncoding, PKCS_CONTENT_INFO, &info,
CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size); CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
@ -5676,11 +5710,15 @@ static void test_encodePKCSAttribute(DWORD dwEncoding)
CRYPT_ATTR_BLOB blob; CRYPT_ATTR_BLOB blob;
char oid[] = "1.2.3"; char oid[] = "1.2.3";
SetLastError(0xdeadbeef); if (0)
ret = pCryptEncodeObjectEx(dwEncoding, PKCS_ATTRIBUTE, NULL, {
CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size); /* Crashes on win9x */
ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION, SetLastError(0xdeadbeef);
"Expected STATUS_ACCESS_VIOLATION, got %x\n", GetLastError()); ret = pCryptEncodeObjectEx(dwEncoding, PKCS_ATTRIBUTE, NULL,
CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION,
"Expected STATUS_ACCESS_VIOLATION, got %x\n", GetLastError());
}
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
ret = pCryptEncodeObjectEx(dwEncoding, PKCS_ATTRIBUTE, &attr, ret = pCryptEncodeObjectEx(dwEncoding, PKCS_ATTRIBUTE, &attr,
CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size); CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);