check that we don't use negative size for arrays

This commit is contained in:
Love Hörnquist Åstrand
2011-12-13 21:52:05 -08:00
parent 2a551314a6
commit 2be0f1a1a4

View File

@@ -47,8 +47,6 @@
#include "gen_locl.h" #include "gen_locl.h"
#include "der.h" #include "der.h"
RCSID("$Id$");
static Type *new_type (Typetype t); static Type *new_type (Typetype t);
static struct constraint_spec *new_constraint_spec(enum ctype); static struct constraint_spec *new_constraint_spec(enum ctype);
static Type *new_tag(int tagclass, int tagvalue, int tagenv, Type *oldtype); static Type *new_tag(int tagclass, int tagvalue, int tagenv, Type *oldtype);
@@ -474,6 +472,11 @@ OctetStringType : kw_OCTET kw_STRING size
{ {
Type *t = new_type(TOctetString); Type *t = new_type(TOctetString);
t->range = $3; t->range = $3;
if (t->range) {
if (t->range->min < 0)
lex_error_message("can't use a negative SIZE range "
"length for OCTET STRING");
}
$$ = new_tag(ASN1_C_UNIV, UT_OctetString, $$ = new_tag(ASN1_C_UNIV, UT_OctetString,
TE_EXPLICIT, t); TE_EXPLICIT, t);
} }
@@ -511,6 +514,11 @@ SequenceOfType : kw_SEQUENCE size kw_OF Type
{ {
$$ = new_type(TSequenceOf); $$ = new_type(TSequenceOf);
$$->range = $2; $$->range = $2;
if ($2) {
if ($2->min < 0)
lex_error_message("can't use a negative SIZE range "
"length for SEQUENCE OF");
}
$$->subtype = $4; $$->subtype = $4;
$$ = new_tag(ASN1_C_UNIV, UT_Sequence, TE_EXPLICIT, $$); $$ = new_tag(ASN1_C_UNIV, UT_Sequence, TE_EXPLICIT, $$);
} }