Parcourir la source

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>
kris/onging/CECPQ3_patch15
David Benjamin il y a 9 ans
committed by Adam Langley
Parent
révision
5933723b7b
2 fichiers modifiés avec 9 ajouts et 2 suppressions
  1. +3
    -1
      crypto/bytestring/bytestring_test.cc
  2. +6
    -1
      crypto/bytestring/cbs.c

+ 3
- 1
crypto/bytestring/bytestring_test.cc Voir le fichier

@@ -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() {


+ 6
- 1
crypto/bytestring/cbs.c Voir le fichier

@@ -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;
}



Chargement…
Annuler
Enregistrer