From f0da24478501cfa8a8cb26b7c0f722cfa725bcce Mon Sep 17 00:00:00 2001 From: Juan Lang Date: Mon, 17 Sep 2007 15:09:16 -0700 Subject: [PATCH] Introduce a helper function to get encoded length that allows indefinite-length encoding --- dlls/crypt32/decode.c | 25 ++++++++++++++++++++----- 1 files changed, 20 insertions(+), 5 deletions(-) diff --git a/dlls/crypt32/decode.c b/dlls/crypt32/decode.c index 0421bd0..67f79d5 100644 --- a/dlls/crypt32/decode.c +++ b/dlls/crypt32/decode.c @@ -135,9 +135,11 @@ #define GET_LEN_BYTES(b) ((b) <= 0x80 ? /* 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 *pbE } 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 *pbE 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 -- 1.4.1