crypt32: Remove exception handling from internal decoding functions.

This commit is contained in:
Juan Lang 2006-06-01 21:23:26 -07:00 committed by Alexandre Julliard
parent 6d668d9d38
commit a7f6a0128c
1 changed files with 74 additions and 104 deletions

View File

@ -1187,98 +1187,88 @@ static BOOL WINAPI CRYPT_AsnDecodeNameValue(DWORD dwCertEncodingType,
PCRYPT_DECODE_PARA pDecodePara, void *pvStructInfo, DWORD *pcbStructInfo) PCRYPT_DECODE_PARA pDecodePara, void *pvStructInfo, DWORD *pcbStructInfo)
{ {
BOOL ret = TRUE; BOOL ret = TRUE;
DWORD dataLen;
CERT_NAME_VALUE *value = (CERT_NAME_VALUE *)pvStructInfo;
__TRY if ((ret = CRYPT_GetLen(pbEncoded, cbEncoded, &dataLen)))
{ {
DWORD dataLen; BYTE lenBytes = GET_LEN_BYTES(pbEncoded[1]);
CERT_NAME_VALUE *value = (CERT_NAME_VALUE *)pvStructInfo;
if ((ret = CRYPT_GetLen(pbEncoded, cbEncoded, &dataLen))) switch (pbEncoded[0])
{ {
BYTE lenBytes = GET_LEN_BYTES(pbEncoded[1]); case ASN_NUMERICSTRING:
case ASN_PRINTABLESTRING:
case ASN_IA5STRING:
break;
default:
FIXME("Unimplemented string type %02x\n", pbEncoded[0]);
SetLastError(OSS_UNIMPLEMENTED);
ret = FALSE;
}
if (ret)
{
DWORD bytesNeeded = sizeof(CERT_NAME_VALUE);
switch (pbEncoded[0]) switch (pbEncoded[0])
{ {
case ASN_NUMERICSTRING: case ASN_NUMERICSTRING:
case ASN_PRINTABLESTRING: case ASN_PRINTABLESTRING:
case ASN_IA5STRING: case ASN_IA5STRING:
if (!(dwFlags & CRYPT_DECODE_NOCOPY_FLAG))
bytesNeeded += dataLen;
break; break;
default: }
FIXME("Unimplemented string type %02x\n", pbEncoded[0]); if (!value)
SetLastError(OSS_UNIMPLEMENTED); *pcbStructInfo = bytesNeeded;
else if (*pcbStructInfo < bytesNeeded)
{
*pcbStructInfo = bytesNeeded;
SetLastError(ERROR_MORE_DATA);
ret = FALSE; ret = FALSE;
} }
if (ret) else
{ {
DWORD bytesNeeded = sizeof(CERT_NAME_VALUE); *pcbStructInfo = bytesNeeded;
switch (pbEncoded[0]) switch (pbEncoded[0])
{ {
case ASN_NUMERICSTRING: case ASN_NUMERICSTRING:
value->dwValueType = CERT_RDN_NUMERIC_STRING;
break;
case ASN_PRINTABLESTRING: case ASN_PRINTABLESTRING:
value->dwValueType = CERT_RDN_PRINTABLE_STRING;
break;
case ASN_IA5STRING: case ASN_IA5STRING:
if (!(dwFlags & CRYPT_DECODE_NOCOPY_FLAG)) value->dwValueType = CERT_RDN_IA5_STRING;
bytesNeeded += dataLen;
break; break;
} }
if (!value) if (dataLen)
*pcbStructInfo = bytesNeeded;
else if (*pcbStructInfo < bytesNeeded)
{ {
*pcbStructInfo = bytesNeeded;
SetLastError(ERROR_MORE_DATA);
ret = FALSE;
}
else
{
*pcbStructInfo = bytesNeeded;
switch (pbEncoded[0]) switch (pbEncoded[0])
{ {
case ASN_NUMERICSTRING: case ASN_NUMERICSTRING:
value->dwValueType = CERT_RDN_NUMERIC_STRING;
break;
case ASN_PRINTABLESTRING: case ASN_PRINTABLESTRING:
value->dwValueType = CERT_RDN_PRINTABLE_STRING;
break;
case ASN_IA5STRING: case ASN_IA5STRING:
value->dwValueType = CERT_RDN_IA5_STRING; value->Value.cbData = dataLen;
if (dwFlags & CRYPT_DECODE_NOCOPY_FLAG)
value->Value.pbData = (BYTE *)pbEncoded + 1 +
lenBytes;
else
{
assert(value->Value.pbData);
memcpy(value->Value.pbData,
pbEncoded + 1 + lenBytes, dataLen);
}
break; break;
} }
if (dataLen) }
{ else
switch (pbEncoded[0]) {
{ value->Value.cbData = 0;
case ASN_NUMERICSTRING: value->Value.pbData = NULL;
case ASN_PRINTABLESTRING:
case ASN_IA5STRING:
value->Value.cbData = dataLen;
if (dwFlags & CRYPT_DECODE_NOCOPY_FLAG)
value->Value.pbData = (BYTE *)pbEncoded + 1 +
lenBytes;
else
{
assert(value->Value.pbData);
memcpy(value->Value.pbData,
pbEncoded + 1 + lenBytes, dataLen);
}
break;
}
}
else
{
value->Value.cbData = 0;
value->Value.pbData = NULL;
}
} }
} }
} }
} }
__EXCEPT_PAGE_FAULT
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
__ENDTRY
return ret; return ret;
} }
@ -1287,41 +1277,31 @@ static BOOL WINAPI CRYPT_AsnDecodeRdnAttr(DWORD dwCertEncodingType,
PCRYPT_DECODE_PARA pDecodePara, void *pvStructInfo, DWORD *pcbStructInfo) PCRYPT_DECODE_PARA pDecodePara, void *pvStructInfo, DWORD *pcbStructInfo)
{ {
BOOL ret; BOOL ret;
struct AsnDecodeSequenceItem items[] = {
{ ASN_OBJECTIDENTIFIER, offsetof(CERT_RDN_ATTR, pszObjId),
CRYPT_AsnDecodeOidInternal, sizeof(LPSTR), FALSE, TRUE,
offsetof(CERT_RDN_ATTR, pszObjId), 0 },
{ 0, offsetof(CERT_RDN_ATTR, dwValueType),
CRYPT_AsnDecodeNameValue, sizeof(CERT_NAME_VALUE),
FALSE, TRUE, offsetof(CERT_RDN_ATTR, Value.pbData), 0 },
};
CERT_RDN_ATTR *attr = (CERT_RDN_ATTR *)pvStructInfo;
TRACE("%p, %ld, %08lx, %p, %ld\n", pbEncoded, cbEncoded, dwFlags, TRACE("%p, %ld, %08lx, %p, %ld\n", pbEncoded, cbEncoded, dwFlags,
pvStructInfo, *pcbStructInfo); pvStructInfo, *pcbStructInfo);
__TRY if (attr)
TRACE("attr->pszObjId is %p\n", attr->pszObjId);
ret = CRYPT_AsnDecodeSequence(X509_ASN_ENCODING, items,
sizeof(items) / sizeof(items[0]), pbEncoded, cbEncoded, dwFlags, NULL,
attr, pcbStructInfo, attr ? attr->pszObjId : NULL);
if (attr)
{ {
struct AsnDecodeSequenceItem items[] = { TRACE("attr->pszObjId is %p (%s)\n", attr->pszObjId,
{ ASN_OBJECTIDENTIFIER, offsetof(CERT_RDN_ATTR, pszObjId), debugstr_a(attr->pszObjId));
CRYPT_AsnDecodeOidInternal, sizeof(LPSTR), FALSE, TRUE, TRACE("attr->dwValueType is %ld\n", attr->dwValueType);
offsetof(CERT_RDN_ATTR, pszObjId), 0 },
{ 0, offsetof(CERT_RDN_ATTR, dwValueType), CRYPT_AsnDecodeNameValue,
sizeof(CERT_NAME_VALUE), FALSE, TRUE, offsetof(CERT_RDN_ATTR,
Value.pbData), 0 },
};
CERT_RDN_ATTR *attr = (CERT_RDN_ATTR *)pvStructInfo;
if (attr)
TRACE("attr->pszObjId is %p\n", attr->pszObjId);
ret = CRYPT_AsnDecodeSequence(X509_ASN_ENCODING, items,
sizeof(items) / sizeof(items[0]), pbEncoded, cbEncoded, dwFlags, NULL,
attr, pcbStructInfo, attr ? attr->pszObjId : NULL);
if (attr)
{
TRACE("attr->pszObjId is %p (%s)\n", attr->pszObjId,
debugstr_a(attr->pszObjId));
TRACE("attr->dwValueType is %ld\n", attr->dwValueType);
}
TRACE("returning %d (%08lx)\n", ret, GetLastError());
} }
__EXCEPT_PAGE_FAULT TRACE("returning %d (%08lx)\n", ret, GetLastError());
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
__ENDTRY
return ret; return ret;
} }
@ -1330,23 +1310,13 @@ static BOOL WINAPI CRYPT_AsnDecodeRdn(DWORD dwCertEncodingType,
PCRYPT_DECODE_PARA pDecodePara, void *pvStructInfo, DWORD *pcbStructInfo) PCRYPT_DECODE_PARA pDecodePara, void *pvStructInfo, DWORD *pcbStructInfo)
{ {
BOOL ret = TRUE; BOOL ret = TRUE;
struct AsnArrayDescriptor arrayDesc = { ASN_CONSTRUCTOR | ASN_SETOF,
CRYPT_AsnDecodeRdnAttr, sizeof(CERT_RDN_ATTR), TRUE,
offsetof(CERT_RDN_ATTR, pszObjId) };
PCERT_RDN rdn = (PCERT_RDN)pvStructInfo;
__TRY ret = CRYPT_AsnDecodeArray(&arrayDesc, pbEncoded, cbEncoded, dwFlags,
{ pDecodePara, pvStructInfo, pcbStructInfo, rdn ? rdn->rgRDNAttr : NULL);
struct AsnArrayDescriptor arrayDesc = { ASN_CONSTRUCTOR | ASN_SETOF,
CRYPT_AsnDecodeRdnAttr, sizeof(CERT_RDN_ATTR), TRUE,
offsetof(CERT_RDN_ATTR, pszObjId) };
PCERT_RDN rdn = (PCERT_RDN)pvStructInfo;
ret = CRYPT_AsnDecodeArray(&arrayDesc, pbEncoded, cbEncoded, dwFlags,
pDecodePara, pvStructInfo, pcbStructInfo, rdn ? rdn->rgRDNAttr : NULL);
}
__EXCEPT_PAGE_FAULT
{
SetLastError(STATUS_ACCESS_VIOLATION);
ret = FALSE;
}
__ENDTRY
return ret; return ret;
} }