Check for leading zeros in CBS_get_asn1_uint64.
The encoding of an INTEGER should not have leading zeros, except to pad for the sign bit. Change-Id: I80d22818cf1d2ca9d27e215620392e1725372aa5 Reviewed-on: https://boringssl-review.googlesource.com/4218 Reviewed-by: Adam Langley <agl@google.com>
This commit is contained in:
parent
0afbcc05e6
commit
5933723b7b
@ -596,8 +596,10 @@ static const ASN1InvalidUint64Test kASN1InvalidUint64Tests[] = {
|
||||
{"\x02\x00", 2},
|
||||
// Negative number.
|
||||
{"\x02\x01\x80", 3},
|
||||
// Overflow
|
||||
// Overflow.
|
||||
{"\x02\x09\x01\x00\x00\x00\x00\x00\x00\x00\x00", 11},
|
||||
// Leading zeros.
|
||||
{"\x02\x02\x00\x01", 4},
|
||||
};
|
||||
|
||||
static bool TestASN1Uint64() {
|
||||
|
@ -291,7 +291,12 @@ int CBS_get_asn1_uint64(CBS *cbs, uint64_t *out) {
|
||||
}
|
||||
|
||||
if ((data[0] & 0x80) != 0) {
|
||||
/* negative number */
|
||||
/* Negative number. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (data[0] == 0 && len > 1 && (data[1] & 0x80) == 0) {
|
||||
/* Extra leading zeros. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user