Commit 4ef01a24 authored by Lev Walkin's avatar Lev Walkin

prohibit encoding universalstring of non-modulo-multiplier size

parent d523ea45
......@@ -1572,14 +1572,22 @@ OCTET_STRING_encode_uper(asn_TYPE_descriptor_t *td,
if(cval->flags & APC_CONSTRAINED)
unit_bits = cval->range_bits;
bpc = OS__BPC_U16;
sizeinunits = st->size / 2;
sizeinunits = st->size >> 1;
if(st->size & 1) {
ASN_DEBUG("%s string size is not modulo 2", td->name);
ASN__ENCODE_FAILED;
}
break;
case ASN_OSUBV_U32:
canonical_unit_bits = unit_bits = 32;
if(cval->flags & APC_CONSTRAINED)
unit_bits = cval->range_bits;
bpc = OS__BPC_U32;
sizeinunits = st->size / 4;
sizeinunits = st->size >> 2;
if(st->size & 3) {
ASN_DEBUG("%s string size is not modulo 4", td->name);
ASN__ENCODE_FAILED;
}
break;
}
......@@ -1599,9 +1607,10 @@ OCTET_STRING_encode_uper(asn_TYPE_descriptor_t *td,
csiz = &asn_DEF_OCTET_STRING_constraints.size;
unit_bits = canonical_unit_bits;
inext = 1;
} else
} else {
ASN__ENCODE_FAILED;
}
}
} else {
inext = 0;
}
......
......@@ -13,6 +13,7 @@ check_PROGRAMS = \
check-XER \
check-OER-INTEGER \
check-OER-NativeEnumerated \
check-PER-UniversalString \
check-PER \
check-PER-INTEGER
......
#include <stdio.h>
#include <assert.h>
#include <sys/time.h>
#include <UniversalString.h>
#include <per_support.h>
static void
check_encode_failed(asn_TYPE_descriptor_t *td, const char *buf, size_t buflen) {
uint8_t uper_output_buffer[32];
UniversalString_t *st_in;
st_in = OCTET_STRING_new_fromBuf(td, buf, buflen);
assert(st_in);
assert(st_in->size == buflen);
asn_enc_rval_t enc =
uper_encode_to_buffer(&asn_DEF_UniversalString, st_in,
uper_output_buffer, sizeof(uper_output_buffer));
assert(enc.encoded == -1);
ASN_STRUCT_FREE(*td, st_in);
}
static void
check_round_trip_OK(asn_TYPE_descriptor_t *td, const char *buf, size_t buflen) {
uint8_t uper_output_buffer[32];
UniversalString_t *st_in;
UniversalString_t *st_out = 0;
st_in = OCTET_STRING_new_fromBuf(td, buf, buflen);
assert(st_in);
assert(st_in->size == buflen);
asn_enc_rval_t enc =
uper_encode_to_buffer(&asn_DEF_UniversalString, st_in,
uper_output_buffer, sizeof(uper_output_buffer));
assert(enc.encoded > 0);
asn_dec_rval_t dec =
uper_decode(0, &asn_DEF_UniversalString, (void **)&st_out,
uper_output_buffer, (enc.encoded + 7) / 8, 0, 0);
assert(dec.consumed == enc.encoded);
assert(st_in->size == st_out->size);
assert(memcmp(st_in->buf, st_out->buf, st_in->size) == 0);
assert(st_out->size == buflen);
assert(memcmp(st_out->buf, buf, buflen) == 0);
ASN_STRUCT_FREE(*td, st_in);
ASN_STRUCT_FREE(*td, st_out);
}
int
main() {
static char UniversalString_data[] = { 0, 0, 0, 65, 0, 0, 0, 65 };
check_round_trip_OK(&asn_DEF_UniversalString, UniversalString_data, 0);
check_encode_failed(&asn_DEF_UniversalString, UniversalString_data, 1);
check_encode_failed(&asn_DEF_UniversalString, UniversalString_data, 2);
check_encode_failed(&asn_DEF_UniversalString, UniversalString_data, 3);
check_round_trip_OK(&asn_DEF_UniversalString, UniversalString_data, 4);
check_encode_failed(&asn_DEF_UniversalString, UniversalString_data, 5);
check_encode_failed(&asn_DEF_UniversalString, UniversalString_data, 6);
check_encode_failed(&asn_DEF_UniversalString, UniversalString_data, 7);
check_round_trip_OK(&asn_DEF_UniversalString, UniversalString_data, 8);
return 0;
}
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