Commit a23f13fe authored by Vasil Velichkov's avatar Vasil Velichkov

Use ASN_STRUCT_RESET to free and reset the OPEN_TYPE memory

Previously when decoding fails the memory was reset with memset after
casting the specifics to asn_CHOICE_specifics_t in order to get the size

The problem is that the OPEN TYPE could contains a different type not
derived from asn_CHOICE that does not have a struct_size member with a
valid size.

This fixes test failures in examples/sample.source.S1AP
parent 86119dfe
...@@ -114,15 +114,12 @@ OPEN_TYPE_ber_get(const asn_codec_ctx_t *opt_codec_ctx, ...@@ -114,15 +114,12 @@ OPEN_TYPE_ber_get(const asn_codec_ctx_t *opt_codec_ctx,
} }
if(*memb_ptr2) { if(*memb_ptr2) {
const asn_CHOICE_specifics_t *specs =
selected.type_descriptor->specifics;
if(elm->flags & ATF_POINTER) { if(elm->flags & ATF_POINTER) {
ASN_STRUCT_FREE(*selected.type_descriptor, inner_value); ASN_STRUCT_FREE(*selected.type_descriptor, inner_value);
*memb_ptr2 = NULL; *memb_ptr2 = NULL;
} else { } else {
ASN_STRUCT_FREE_CONTENTS_ONLY(*selected.type_descriptor, ASN_STRUCT_RESET(*selected.type_descriptor,
inner_value); inner_value);
memset(*memb_ptr2, 0, specs->struct_size);
} }
} }
return rv; return rv;
...@@ -236,15 +233,12 @@ OPEN_TYPE_xer_get(const asn_codec_ctx_t *opt_codec_ctx, ...@@ -236,15 +233,12 @@ OPEN_TYPE_xer_get(const asn_codec_ctx_t *opt_codec_ctx,
* will have to be restarted. * will have to be restarted.
*/ */
if(*memb_ptr2) { if(*memb_ptr2) {
const asn_CHOICE_specifics_t *specs =
selected.type_descriptor->specifics;
if(elm->flags & ATF_POINTER) { if(elm->flags & ATF_POINTER) {
ASN_STRUCT_FREE(*selected.type_descriptor, inner_value); ASN_STRUCT_FREE(*selected.type_descriptor, inner_value);
*memb_ptr2 = NULL; *memb_ptr2 = NULL;
} else { } else {
ASN_STRUCT_FREE_CONTENTS_ONLY(*selected.type_descriptor, ASN_STRUCT_RESET(*selected.type_descriptor,
inner_value); inner_value);
memset(*memb_ptr2, 0, specs->struct_size);
} }
} }
return rv; return rv;
...@@ -352,15 +346,12 @@ OPEN_TYPE_uper_get(const asn_codec_ctx_t *opt_codec_ctx, ...@@ -352,15 +346,12 @@ OPEN_TYPE_uper_get(const asn_codec_ctx_t *opt_codec_ctx,
case RC_WMORE: case RC_WMORE:
case RC_FAIL: case RC_FAIL:
if(*memb_ptr2) { if(*memb_ptr2) {
const asn_CHOICE_specifics_t *specs =
selected.type_descriptor->specifics;
if(elm->flags & ATF_POINTER) { if(elm->flags & ATF_POINTER) {
ASN_STRUCT_FREE(*selected.type_descriptor, inner_value); ASN_STRUCT_FREE(*selected.type_descriptor, inner_value);
*memb_ptr2 = NULL; *memb_ptr2 = NULL;
} else { } else {
ASN_STRUCT_FREE_CONTENTS_ONLY(*selected.type_descriptor, ASN_STRUCT_RESET(*selected.type_descriptor,
inner_value); inner_value);
memset(*memb_ptr2, 0, specs->struct_size);
} }
} }
} }
...@@ -465,15 +456,12 @@ OPEN_TYPE_aper_get(const asn_codec_ctx_t *opt_codec_ctx, ...@@ -465,15 +456,12 @@ OPEN_TYPE_aper_get(const asn_codec_ctx_t *opt_codec_ctx,
case RC_WMORE: case RC_WMORE:
case RC_FAIL: case RC_FAIL:
if(*memb_ptr2) { if(*memb_ptr2) {
const asn_CHOICE_specifics_t *specs =
selected.type_descriptor->specifics;
if(elm->flags & ATF_POINTER) { if(elm->flags & ATF_POINTER) {
ASN_STRUCT_FREE(*selected.type_descriptor, inner_value); ASN_STRUCT_FREE(*selected.type_descriptor, inner_value);
*memb_ptr2 = NULL; *memb_ptr2 = NULL;
} else { } else {
ASN_STRUCT_FREE_CONTENTS_ONLY(*selected.type_descriptor, ASN_STRUCT_RESET(*selected.type_descriptor,
inner_value); inner_value);
memset(*memb_ptr2, 0, specs->struct_size);
} }
} }
} }
......
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