From 4e300b6defe488feecb36a5cab223c6c78998c66 Mon Sep 17 00:00:00 2001 From: Juan Lang Date: Thu, 15 Oct 2009 15:12:40 -0700 Subject: [PATCH] crypt32: Simplify CRYPT_AsnDecodeIntInternal. --- dlls/crypt32/decode.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/dlls/crypt32/decode.c b/dlls/crypt32/decode.c index 9da367bc4d4..ede5af2f4e9 100644 --- a/dlls/crypt32/decode.c +++ b/dlls/crypt32/decode.c @@ -3915,38 +3915,40 @@ static BOOL CRYPT_AsnDecodeIntInternal(const BYTE *pbEncoded, DWORD cbEncoded, DWORD dwFlags, void *pvStructInfo, DWORD *pcbStructInfo, DWORD *pcbDecoded) { BOOL ret; - BYTE buf[sizeof(CRYPT_INTEGER_BLOB) + sizeof(int)]; - CRYPT_INTEGER_BLOB *blob = (CRYPT_INTEGER_BLOB *)buf; - DWORD size = sizeof(buf); + DWORD dataLen; - blob->pbData = buf + sizeof(CRYPT_INTEGER_BLOB); - ret = CRYPT_AsnDecodeIntegerInternal(pbEncoded, cbEncoded, 0, buf, - &size, pcbDecoded); - if (ret) + if ((ret = CRYPT_GetLen(pbEncoded, cbEncoded, &dataLen))) { - if (!pvStructInfo) + BYTE lenBytes = GET_LEN_BYTES(pbEncoded[1]); + + if (pcbDecoded) + *pcbDecoded = 1 + lenBytes + dataLen; + if (dataLen > sizeof(int)) + { + SetLastError(CRYPT_E_ASN1_LARGE); + ret = FALSE; + } + else if (!pvStructInfo) *pcbStructInfo = sizeof(int); else if ((ret = CRYPT_DecodeCheckSpace(pcbStructInfo, sizeof(int)))) { int val, i; - if (blob->pbData[blob->cbData - 1] & 0x80) + if (dataLen && pbEncoded[1 + lenBytes] & 0x80) { /* initialize to a negative value to sign-extend */ val = -1; } else val = 0; - for (i = 0; i < blob->cbData; i++) + for (i = 0; i < dataLen; i++) { val <<= 8; - val |= blob->pbData[blob->cbData - i - 1]; + val |= pbEncoded[1 + lenBytes + i]; } memcpy(pvStructInfo, &val, sizeof(int)); } } - else if (GetLastError() == ERROR_MORE_DATA) - SetLastError(CRYPT_E_ASN1_LARGE); return ret; }