Skip to content

Commit

Permalink
Committed "aper: workaround for undefined enumeration indexes" by Krz…
Browse files Browse the repository at this point in the history
…ysztof Witek <[email protected]>

commit a12c7fa from vlm/asn1c #115
  • Loading branch information
mouse07410 committed Jun 23, 2020
1 parent de0d9ea commit 100e622
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
14 changes: 11 additions & 3 deletions skeletons/NativeEnumerated.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,19 @@ NativeEnumerated_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
/*
* X.691, #10.6: normally small non-negative whole number;
*/
value = uper_get_nsnnwn(pd);
//value = uper_get_nsnnwn(pd);
/* XXX handle indefinite index length > 64k */
value = aper_get_nsnnwn(pd, 65537);
if(value < 0) ASN__DECODE_STARVED;
value += specs->extension - 1;
if(value >= specs->map_count)
ASN__DECODE_FAILED;
//if(value >= specs->map_count)
// ASN__DECODE_FAILED;
if(value >= specs->map_count) {
ASN_DEBUG("Decoded unknown index value %s = %ld", td->name, value);
/* unknown index. Workaround => set the first enumeration value */
*native = specs->value2enum[0].nat_value;
return rval;
}
}

*native = specs->value2enum[value].nat_value;
Expand Down
20 changes: 19 additions & 1 deletion skeletons/per_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,25 @@ aper_get_nsnnwn(asn_per_data_t *pd, int range) {
/* 2 bytes */
bytes = 2;
} else {
return -1;
//return -1;
int length;

/* handle indefinite range */
length = per_get_few_bits(pd, 1);
if (length == 0)
return per_get_few_bits(pd, 6);

if (aper_get_align(pd) < 0)
return -1;

length = per_get_few_bits(pd, 8);
/* the length is not likely to be that big */
if (length > 4)
return -1;
value = 0;
if (per_get_many_bits(pd, (uint8_t *)&value, 0, length * 8) < 0)
return -1;
return value;
}
if (aper_get_align(pd) < 0)
return -1;
Expand Down

0 comments on commit 100e622

Please sign in to comment.