Commit 5de82742 authored by Lev Walkin's avatar Lev Walkin

fix UPER BIT STRING trailer encoding

parent ba2c5727
......@@ -487,17 +487,20 @@ BIT_STRING_encode_uper(const asn_TYPE_descriptor_t *td,
if(csiz->effective_bits >= 0 && !inext) {
int add_trailer = (ssize_t)size_in_bits < csiz->lower_bound;
ASN_DEBUG("Encoding %zu bytes (%ld), length in %d bits", st->size,
size_in_bits - csiz->lower_bound, csiz->effective_bits);
ASN_DEBUG(
"Encoding %zu bytes (%ld), length (in %d bits) trailer %d; actual "
"value %zd",
st->size, size_in_bits - csiz->lower_bound, csiz->effective_bits,
add_trailer,
add_trailer ? 0 : (ssize_t)size_in_bits - csiz->lower_bound);
ret = per_put_few_bits(
po,
add_trailer ? csiz->lower_bound : (ssize_t)size_in_bits - csiz->lower_bound,
po, add_trailer ? 0 : (ssize_t)size_in_bits - csiz->lower_bound,
csiz->effective_bits);
if(ret) ASN__ENCODE_FAILED;
ret = per_put_many_bits(po, st->buf, size_in_bits);
if(ret) ASN__ENCODE_FAILED;
if(add_trailer) {
static uint8_t zeros[16];
static const uint8_t zeros[16];
size_t trailing_zero_bits = csiz->lower_bound - size_in_bits;
while(trailing_zero_bits > 0) {
if(trailing_zero_bits > 8 * sizeof(zeros)) {
......@@ -623,6 +626,7 @@ BIT_STRING_random_fill(const asn_TYPE_descriptor_t *td, void **sptr,
for(b = buf; b < bend; b++) {
*(uint8_t *)b = asn_random_between(0, 255);
}
*b = 0; /* Zero-terminate just in case. */
if(*sptr) {
st = *sptr;
......
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