crypt32: Allow items in an array to be indefinite-length encoded.

This commit is contained in:
Juan Lang 2007-09-17 17:02:19 -07:00 committed by Alexandre Julliard
parent 5d168bd4c0
commit 52be131a29
1 changed files with 13 additions and 15 deletions

View File

@ -574,23 +574,25 @@ static BOOL CRYPT_AsnDecodeArray(const struct AsnArrayDescriptor *arrayDesc,
doneDecoding = TRUE; doneDecoding = TRUE;
if (!doneDecoding) if (!doneDecoding)
{ {
DWORD itemDataLen, itemDecoded, size = 0; DWORD itemEncoded, itemDataLen, itemDecoded, size = 0;
/* Each item decoded may not tolerate extraneous bytes, /* Each item decoded may not tolerate extraneous bytes,
* so get the length of the next element and pass it * so get the length of the next element if known.
* directly.
*/ */
ret = CRYPT_GetLen(ptr, cbEncoded - (ptr - pbEncoded), if ((ret = CRYPT_GetLengthIndefinite(ptr,
&itemDataLen); cbEncoded - (ptr - pbEncoded), &itemDataLen)))
{
if (itemDataLen == CMSG_INDEFINITE_LENGTH)
itemEncoded = cbEncoded - (ptr - pbEncoded);
else
itemEncoded = 1 + itemLenBytes + itemDataLen;
}
if (ret) if (ret)
ret = arrayDesc->decodeFunc(ptr, ret = arrayDesc->decodeFunc(ptr, itemEncoded,
1 + itemLenBytes + itemDataLen,
dwFlags & ~CRYPT_DECODE_ALLOC_FLAG, NULL, &size, dwFlags & ~CRYPT_DECODE_ALLOC_FLAG, NULL, &size,
&itemDecoded); &itemDecoded);
if (ret) if (ret)
{ {
DWORD nextLen;
cItems++; cItems++;
if (itemSizes != &itemSize) if (itemSizes != &itemSize)
itemSizes = CryptMemRealloc(itemSizes, itemSizes = CryptMemRealloc(itemSizes,
@ -607,14 +609,10 @@ static BOOL CRYPT_AsnDecodeArray(const struct AsnArrayDescriptor *arrayDesc,
if (itemSizes) if (itemSizes)
{ {
decoded += itemDecoded; decoded += itemDecoded;
itemSizes[cItems - 1].encodedLen = itemSizes[cItems - 1].encodedLen = itemEncoded;
1 + itemLenBytes + itemDataLen;
itemSizes[cItems - 1].size = size; itemSizes[cItems - 1].size = size;
bytesNeeded += size; bytesNeeded += size;
ret = CRYPT_GetLen(ptr, ptr += itemEncoded;
cbEncoded - (ptr - pbEncoded), &nextLen);
if (ret)
ptr += nextLen + 1 + GET_LEN_BYTES(ptr[1]);
} }
else else
ret = FALSE; ret = FALSE;