Commit 3f8f6c8f authored by Pau Espin Pedrol's avatar Pau Espin Pedrol Committed by Mouse

tests-skeletons/check-APER-support: Showcase bug in aper_put_length()

This commit adds a test case which shows a bug introduced in
0101252e [1].

As a result, a small value (under 1 octet) with range spanning full 2
octets (65536) is encoded incorrectly as 1 octet.

Section 4 of X.691 defines 64K as 65536, and Section 11.5.7 explicitly states
"""
c) "range" is greater than 256 and less than or equal to 64K (the two-octet case).
"""

[1] https://github.com/mouse07410/asn1c/pull/91
parent ccf897b5
...@@ -105,9 +105,31 @@ check_encode_number_greater_than_range() { ...@@ -105,9 +105,31 @@ check_encode_number_greater_than_range() {
assert(may_write < 0); assert(may_write < 0);
} }
/*
* Checks that a value which can be put in 1 byte (<256) but with a range type
* of 2 bytes (65536) is encoded as 2 octets.
*/
static void
check_range65536_encoded_as_2octet() {
asn_per_outp_t po;
int range = 65536;
size_t length = 5;
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);
unsigned int bytes_needed = (po.buffer - po.tmpspace) + po.nboff/8;
fprintf(stderr, "\naper_put_length(range=%d, len=%zu) => bytes_needed=%u\n",
range, length, bytes_needed);
assert(bytes_needed == 1); /* BUG: should be 2 octets! */
}
int main() { int main() {
check_round_trips_range65536(); check_round_trips_range65536();
check_encode_number_greater_than_range(); check_encode_number_greater_than_range();
check_range65536_encoded_as_2octet();
} }
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