fixed undefined behavior when parsing negative ASN.1 Integer
This commit is contained in:
parent
3e110995bc
commit
f621305140
|
@ -707,17 +707,19 @@ static int encode_bit_field(const u8 *inbuf, size_t inlen,
|
|||
|
||||
int sc_asn1_decode_integer(const u8 * inbuf, size_t inlen, int *out)
|
||||
{
|
||||
int a = 0;
|
||||
int a = 0, is_negative = 0;
|
||||
size_t i;
|
||||
|
||||
if (inlen > sizeof(int) || inlen == 0)
|
||||
return SC_ERROR_INVALID_ASN1_OBJECT;
|
||||
if (inbuf[0] & 0x80)
|
||||
a = -1;
|
||||
is_negative = 1;
|
||||
for (i = 0; i < inlen; i++) {
|
||||
a <<= 8;
|
||||
a |= *inbuf++;
|
||||
}
|
||||
if (is_negative)
|
||||
a *= -1;
|
||||
*out = a;
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue