From 7ecf5becbd9ce7f62a80cc4294db1f44a62a17c1 Mon Sep 17 00:00:00 2001 From: Juan Lang Date: Mon, 17 Sep 2007 15:09:16 -0700 Subject: [PATCH] crypt32: Introduce a helper function to get encoded length that allows indefinite-length encoding. --- dlls/crypt32/decode.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/dlls/crypt32/decode.c b/dlls/crypt32/decode.c index 0421bd0ab37..67f79d5bcb5 100644 --- a/dlls/crypt32/decode.c +++ b/dlls/crypt32/decode.c @@ -135,9 +135,11 @@ static BOOL WINAPI CRYPT_AsnDecodeUnsignedIntegerInternal( /* Helper function to get the encoded length of the data starting at pbEncoded, * where pbEncoded[0] is the tag. If the data are too short to contain a * length or if the length is too large for cbEncoded, sets an appropriate - * error code and returns FALSE. + * error code and returns FALSE. If the encoded length is unknown due to + * indefinite length encoding, *len is set to CMSG_INDEFINITE_LENGTH. */ -static BOOL CRYPT_GetLen(const BYTE *pbEncoded, DWORD cbEncoded, DWORD *len) +static BOOL CRYPT_GetLengthIndefinite(const BYTE *pbEncoded, DWORD cbEncoded, + DWORD *len) { BOOL ret; @@ -161,9 +163,8 @@ static BOOL CRYPT_GetLen(const BYTE *pbEncoded, DWORD cbEncoded, DWORD *len) } else if (pbEncoded[1] == 0x80) { - FIXME("unimplemented for indefinite-length encoding\n"); - SetLastError(CRYPT_E_ASN1_CORRUPT); - ret = FALSE; + *len = CMSG_INDEFINITE_LENGTH; + ret = TRUE; } else { @@ -204,6 +205,20 @@ static BOOL CRYPT_GetLen(const BYTE *pbEncoded, DWORD cbEncoded, DWORD *len) return ret; } +/* Like CRYPT_GetLengthIndefinite, but disallows indefinite-length encoding. */ +static BOOL CRYPT_GetLen(const BYTE *pbEncoded, DWORD cbEncoded, DWORD *len) +{ + BOOL ret; + + if ((ret = CRYPT_GetLengthIndefinite(pbEncoded, cbEncoded, len)) && + *len == CMSG_INDEFINITE_LENGTH) + { + SetLastError(CRYPT_E_ASN1_CORRUPT); + ret = FALSE; + } + return ret; +} + /* Helper function to check *pcbStructInfo, set it to the required size, and * optionally to allocate memory. Assumes pvStructInfo is not NULL. * If CRYPT_DECODE_ALLOC_FLAG is set in dwFlags, *pvStructInfo will be set to a