Skip to content

Commit

Permalink
der/asn1: don't pass on more data than is specified
Browse files Browse the repository at this point in the history
Set and Sequence parsers would pass on max available data instead
of the size of their object.

Malformed data could trigger massive recursion this way, leading
to spending much more resources than necessary.

Found using AFL.

Bug #3184.
  • Loading branch information
victorjulien committed Sep 23, 2019
1 parent 8c399c0 commit 9dfdb3e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/util-decode-der.c
Expand Up @@ -846,8 +846,9 @@ static Asn1Generic * DecodeAsn1DerSequence(const unsigned char *buffer,
while (parsed_bytes < d_length) {
el_max_size = max_size - (d_ptr-buffer);

Asn1Generic *child = DecodeAsn1DerGeneric(d_ptr, el_max_size, depth,
seq_index, errcode);
Asn1Generic *child = DecodeAsn1DerGeneric(d_ptr,
MIN(node->length, el_max_size), depth,
seq_index, errcode);
if (child == NULL) {
if (*errcode != 0) {
DerFree(node);
Expand Down Expand Up @@ -924,7 +925,8 @@ static Asn1Generic * DecodeAsn1DerSet(const unsigned char *buffer,

el_max_size = max_size - (d_ptr-buffer);

child = DecodeAsn1DerGeneric(d_ptr, el_max_size, depth, seq_index, errcode);
child = DecodeAsn1DerGeneric(d_ptr, MIN(node->length, el_max_size),
depth, seq_index, errcode);
if (child == NULL) {
DerFree(node);
return NULL;
Expand Down

0 comments on commit 9dfdb3e

Please sign in to comment.