Commit ccf897b5 authored by Pau Espin Pedrol's avatar Pau Espin Pedrol Committed by Mouse

APER encoding: Fix aper_put_nsnnwn when value > range

parent 60ee1206
......@@ -232,8 +232,12 @@ aper_put_nsnnwn(asn_per_outp_t *po, int range, int number) {
}
return per_put_few_bits(po, number, i);
} else if(range == 256) {
if (number >= range)
return -1;
bytes = 1;
} else if(range <= 65536) {
if (number >= range)
return -1;
bytes = 2;
} else { /* Ranges > 64K */
int i;
......
......@@ -77,6 +77,7 @@ check_round_trips_range65536() {
check_round_trip(65536, 65534);
check_round_trip(65536, 65535);
check_round_trip(65536, 65536);
/* BUG: ^ this should fail but there's another unrelated bug, will be fixed in follow-up commit */
}
/*
......@@ -87,12 +88,21 @@ check_encode_number_greater_than_range() {
asn_per_outp_t po;
int range = 6500;
size_t length = 6503;
ssize_t may_write;
memset(&po, 0, sizeof(po));
po.buffer = po.tmpspace;
po.nbits = 8 * sizeof(po.tmpspace);
ssize_t may_write = aper_put_length(&po, range, length, NULL);
assert(may_write >= 0); /* BUG, this should fail! */
may_write = aper_put_length(&po, range, length, NULL);
assert(may_write < 0);
/* Also check value = range should fail: */
memset(&po, 0, sizeof(po));
po.buffer = po.tmpspace;
po.nbits = 8 * sizeof(po.tmpspace);
length = range;
may_write = aper_put_length(&po, range, length, NULL);
assert(may_write < 0);
}
int main() {
......
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