Commit 1351752f authored by Lev Walkin's avatar Lev Walkin

fixed non-trivial SIZE constraints for SET OF and SEQUENCE OF, fuzz-tested

parent 24354e1c
......@@ -177,13 +177,14 @@ SEQUENCE_OF_encode_uper(const asn_TYPE_descriptor_t *td,
ASN__ENCODE_FAILED;
}
if(ct && ct->effective_bits >= 0) {
/* X.691, #19.5: No length determinant */
if(per_put_few_bits(po, list->count - ct->lower_bound,
ct->effective_bits))
ASN__ENCODE_FAILED;
}
} else if (list->count == 0) {
}
if(ct && ct->effective_bits >= 0) {
/* X.691, #19.5: No length determinant */
if(per_put_few_bits(po, list->count - ct->lower_bound,
ct->effective_bits))
ASN__ENCODE_FAILED;
} else if(list->count == 0) {
/* When the list is empty add only the length determinant
* X.691, #20.6 and #11.9.4.1
*/
......@@ -193,7 +194,6 @@ SEQUENCE_OF_encode_uper(const asn_TYPE_descriptor_t *td,
ASN__ENCODED_OK(er);
}
for(encoded_edx = 0; (ssize_t)encoded_edx < list->count;) {
ssize_t may_encode;
size_t edx;
......
......@@ -1038,14 +1038,24 @@ SET_OF_encode_uper(const asn_TYPE_descriptor_t *td,
ASN__ENCODE_FAILED;
}
if(ct && ct->effective_bits >= 0) {
/* X.691, #19.5: No length determinant */
if(per_put_few_bits(po, list->count - ct->lower_bound,
ct->effective_bits))
ASN__ENCODE_FAILED;
}
if(ct && ct->effective_bits >= 0) {
/* X.691, #19.5: No length determinant */
if(per_put_few_bits(po, list->count - ct->lower_bound,
ct->effective_bits))
ASN__ENCODE_FAILED;
} else if(list->count == 0) {
/* When the list is empty add only the length determinant
* X.691, #20.6 and #11.9.4.1
*/
if (uper_put_length(po, 0, 0)) {
ASN__ENCODE_FAILED;
}
ASN__ENCODED_OK(er);
}
/*
* Canonical UPER #22.1 mandates dynamic sorting of the SET OF elements
* according to their encodings. Build an array of the encoded elements.
......@@ -1249,8 +1259,48 @@ SET_OF_random_fill(const asn_TYPE_descriptor_t *td, void **sptr,
}
/* Bias towards edges of allowed space */
switch(asn_random_between(0, 4)) {
switch(asn_random_between(-1, 4)) {
default:
case -1:
/* Prepare lengths somewhat outside of constrained range. */
if(constraints->per_constraints
&& (constraints->per_constraints->size.flags & APC_EXTENSIBLE)) {
switch(asn_random_between(0, 5)) {
default:
case 0:
rnd_len = 0;
break;
case 1:
if(slb > 0) {
rnd_len = slb - 1;
} else {
rnd_len = 0;
}
break;
case 2:
rnd_len = asn_random_between(0, slb);
break;
case 3:
if(sub < (ssize_t)max_length) {
rnd_len = sub + 1;
} else {
rnd_len = max_length;
}
break;
case 4:
if(sub < (ssize_t)max_length) {
rnd_len = asn_random_between(sub + 1, max_length);
} else {
rnd_len = max_length;
}
break;
case 5:
rnd_len = max_length;
break;
}
break;
}
/* Fall through */
case 0:
rnd_len = asn_random_between(slb, sub);
break;
......
......@@ -78,3 +78,13 @@ SEQUENCE { ..., null NULL, ..., one [1] NULL, two BOOLEAN, three BIT STRING (SIZ
SEQUENCE { one BOOLEAN OPTIONAL, two PrintableString (SIZE(1)), three VisibleString (SIZE(1)) DEFAULT "Z" }
SEQUENCE { one [1] BOOLEAN OPTIONAL, two [2] BOOLEAN, three [3] BOOLEAN DEFAULT TRUE, four PrintableString (SIZE(1)), five VisibleString (SIZE(1)) DEFAULT "Z" }
SEQUENCE { list SEQUENCE OF PrintableString (SIZE(1)), guard OCTET STRING (SIZE(1)) } -- RMAX=16385
-- Mainly verifies list encoding when its size is 0.
SEQUENCE { list SET OF OCTET STRING(SIZE(1)), guard OCTET STRING(SIZE(1)) }
SEQUENCE { list SET (SIZE(1..MAX)) OF OCTET STRING(SIZE(1)), guard OCTET STRING(SIZE(1)) }
SEQUENCE { list SET (SIZE(1..MAX,...)) OF OCTET STRING(SIZE(1)), guard OCTET STRING(SIZE(1)) }
SEQUENCE { list SET (SIZE(1..2,...)) OF OCTET STRING(SIZE(1)), guard OCTET STRING(SIZE(1)) }
SEQUENCE { list SEQUENCE OF OCTET STRING(SIZE(1)), guard OCTET STRING(SIZE(1)) }
SEQUENCE { list SEQUENCE (SIZE(1..MAX,...)) OF OCTET STRING(SIZE(1)), guard OCTET STRING(SIZE(1)) }
SEQUENCE { list SEQUENCE (SIZE(1..2,...)) OF OCTET STRING(SIZE(1)), guard OCTET STRING(SIZE(1)) }
......@@ -31,3 +31,8 @@ SEQUENCE OF PrintableString (FROM("A".."Z"))
SEQUENCE OF BOOLEAN -- RMAX=70000
SEQUENCE (SIZE(2..MAX)) OF BOOLEAN -- RMAX=70000
SEQUENCE OF PrintableString (SIZE(1)) --RMAX=16384
-- Mainly verifies encoding when its size is 0.
SEQUENCE OF OCTET STRING (SIZE(1))
SEQUENCE (SIZE(1..MAX,...)) OF OCTET STRING (SIZE(1))
SEQUENCE (SIZE(1..2,...)) OF OCTET STRING (SIZE(1))
......@@ -31,3 +31,8 @@ SET OF PrintableString (FROM("A".."Z"))
SET OF BOOLEAN -- RMAX=70000
SET (SIZE(2..MAX)) OF BOOLEAN -- RMAX=70000
SET OF PrintableString (SIZE(1)) --RMAX=16384
-- Mainly verifies encoding when its size is 0.
SET OF OCTET STRING (SIZE(1))
SET (SIZE(1..MAX,...)) OF OCTET STRING (SIZE(1))
SET (SIZE(1..2,...)) OF OCTET STRING (SIZE(1))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment