diff --git a/crypto/asn1/asn1_lib.c b/crypto/asn1/asn1_lib.c index ea727f33..8526aba3 100644 --- a/crypto/asn1/asn1_lib.c +++ b/crypto/asn1/asn1_lib.c @@ -205,7 +205,11 @@ static int asn1_get_length(const unsigned char **pp, int *inf, long *rl, } else ret = i; } - if (ret > LONG_MAX) + /* + * Bound the length to comfortably fit in an int. Lengths in this module + * often switch between int and long without overflow checks. + */ + if (ret > INT_MAX / 2) return 0; *pp = p; *rl = (long)ret;