Skip to content

Commit

Permalink
der/asn1: limit recursion
Browse files Browse the repository at this point in the history
Limit the number of recursive calls in the DER/ASN.1 decoder to avoid
stack overflows.

Found using AFL.
  • Loading branch information
victorjulien committed Jul 13, 2017
1 parent a306ccf commit df3a3c7
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/util-decode-der.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ static Asn1Generic * DecodeAsn1DerGeneric(const unsigned char *buffer,
Asn1Generic *child;
uint8_t el_type;

/* refuse excessive recursion */
if (unlikely(depth == 255)) {
return NULL;
}

el.cls = (d_ptr[0] & 0xc0) >> 6;
el.pc = (d_ptr[0] & 0x20) >> 5;
el.tag = (d_ptr[0] & 0x1f);
Expand Down

0 comments on commit df3a3c7

Please sign in to comment.