diff options
-rw-r--r-- | skeletons/NULL.c | 13 | ||||
-rw-r--r-- | skeletons/constr_SEQUENCE.c | 10 | ||||
-rw-r--r-- | skeletons/constr_SEQUENCE_oer.c | 39 | ||||
-rw-r--r-- | skeletons/oer_encoder.c | 2 | ||||
-rw-r--r-- | skeletons/oer_encoder.h | 4 | ||||
-rw-r--r-- | tests/tests-randomized/Makefile.am | 1 | ||||
-rw-r--r-- | tests/tests-randomized/bundles/16-SEQUENCE-bundle.txt | 69 |
7 files changed, 118 insertions, 20 deletions
diff --git a/skeletons/NULL.c b/skeletons/NULL.c index 77a377e1..a43d412b 100644 --- a/skeletons/NULL.c +++ b/skeletons/NULL.c @@ -135,15 +135,24 @@ NULL_print(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, asn_dec_rval_t NULL_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, const asn_TYPE_descriptor_t *td, - const asn_oer_constraints_t *constraints, void **struct_ptr, + const asn_oer_constraints_t *constraints, void **sptr, const void *ptr, size_t size) { asn_dec_rval_t rv = {RC_OK, 0}; (void)opt_codec_ctx; (void)td; (void)constraints; - (void)struct_ptr; (void)ptr; (void)size; + + if(!*sptr) { + *sptr = MALLOC(sizeof(NULL_t)); + if(*sptr) { + *(NULL_t *)*sptr = 0; + } else { + ASN__DECODE_FAILED; + } + } + return rv; } diff --git a/skeletons/constr_SEQUENCE.c b/skeletons/constr_SEQUENCE.c index 85df7a6a..d080ccb0 100644 --- a/skeletons/constr_SEQUENCE.c +++ b/skeletons/constr_SEQUENCE.c @@ -1517,8 +1517,18 @@ SEQUENCE_compare(const asn_TYPE_descriptor_t *td, const void *aptr, *(const void *const *)((const char *)bptr + elm->memb_offset); if(!amemb) { if(!bmemb) continue; + if(elm->default_value_cmp + && elm->default_value_cmp(bmemb) == 0) { + /* A is absent, but B is present and equal to DEFAULT */ + continue; + } return -1; } else if(!bmemb) { + if(elm->default_value_cmp + && elm->default_value_cmp(amemb) == 0) { + /* B is absent, but A is present and equal to DEFAULT */ + continue; + } return 1; } } else { diff --git a/skeletons/constr_SEQUENCE_oer.c b/skeletons/constr_SEQUENCE_oer.c index 9906af9d..2c11fa46 100644 --- a/skeletons/constr_SEQUENCE_oer.c +++ b/skeletons/constr_SEQUENCE_oer.c @@ -207,9 +207,10 @@ SEQUENCE_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, memb_ptr2 = element_ptrptr(st, elm, &save_memb_ptr); - rval = elm->type->op->oer_decoder(opt_codec_ctx, elm->type, - elm->encoding_constraints.oer_constraints, - memb_ptr2, ptr, size); + rval = elm->type->op->oer_decoder( + opt_codec_ctx, elm->type, + elm->encoding_constraints.oer_constraints, memb_ptr2, ptr, + size); } switch(rval.code) { case RC_OK: @@ -268,7 +269,7 @@ SEQUENCE_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, len_len = oer_fetch_length(ptr, size, &len); if(len_len > 0) { ADVANCE(len_len); - } if(len_len < 0) { + } else if(len_len < 0) { RETURN(RC_FAIL); } else { RETURN(RC_WMORE); @@ -314,7 +315,8 @@ SEQUENCE_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, asn_bit_data_t *extadds = ctx->ptr; size_t edx = ctx->step; asn_TYPE_member_t *elm = &td->elements[edx]; - void **memb_ptr2 = element_ptrptr(st, elm, 0); + void *tmp_memb_ptr; + void **memb_ptr2 = element_ptrptr(st, elm, &tmp_memb_ptr); switch(asn_get_few_bits(extadds, 1)) { case -1: @@ -332,9 +334,11 @@ SEQUENCE_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, continue; case 1: { /* Read OER open type */ - ssize_t ot_size = oer_open_type_get(opt_codec_ctx, elm->type, - elm->encoding_constraints.oer_constraints, - memb_ptr2, ptr, size); + ssize_t ot_size = + oer_open_type_get(opt_codec_ctx, elm->type, + elm->encoding_constraints.oer_constraints, + memb_ptr2, ptr, size); + assert(ot_size <= (ssize_t)size); if(ot_size > 0) { ADVANCE(ot_size); } else if(ot_size < 0) { @@ -342,8 +346,12 @@ SEQUENCE_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, } else { /* Roll back open type parsing */ asn_get_undo(extadds, 1); - ASN_STRUCT_FREE(*elm->type, *memb_ptr2); - *memb_ptr2 = NULL; + if(memb_ptr2 == &tmp_memb_ptr) { + ASN_STRUCT_RESET(*elm->type, *memb_ptr2); + } else { + ASN_STRUCT_FREE(*elm->type, *memb_ptr2); + *memb_ptr2 = NULL; + } RETURN(RC_WMORE); } break; @@ -385,7 +393,7 @@ SEQUENCE_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, } } - return rval; + RETURN(RC_OK); } /* @@ -552,13 +560,14 @@ SEQUENCE_encode_oer(const asn_TYPE_descriptor_t *td, && elm->default_value_cmp(memb_ptr) == 0) { /* Do not encode default value. */ } else { - asn_enc_rval_t er = elm->type->op->oer_encoder( + ssize_t wrote = oer_open_type_put( elm->type, elm->encoding_constraints.oer_constraints, memb_ptr, cb, app_key); - if(er.encoded == -1) { - return er; + ASN_DEBUG("Open type %s encoded in %zd, +computed=%zu", elm->type->name, wrote, computed_size); + if(wrote == -1) { + ASN__ENCODE_FAILED; } - computed_size += er.encoded; + computed_size += wrote; } } else if(!elm->optional) { ASN__ENCODE_FAILED; diff --git a/skeletons/oer_encoder.c b/skeletons/oer_encoder.c index 4b7d7dac..1a691ed4 100644 --- a/skeletons/oer_encoder.c +++ b/skeletons/oer_encoder.c @@ -136,6 +136,6 @@ oer_open_type_put(const asn_TYPE_descriptor_t *td, if(er.encoded < 0) return -1; assert(serialized_byte_count == (size_t)er.encoded); - return er.encoded + len_len; + return len_len + er.encoded; } diff --git a/skeletons/oer_encoder.h b/skeletons/oer_encoder.h index 252bd6a5..6a7b6812 100644 --- a/skeletons/oer_encoder.h +++ b/skeletons/oer_encoder.h @@ -48,8 +48,8 @@ typedef asn_enc_rval_t(oer_type_encoder_f)( /* * Write out the Open Type (X.696 (08/2015), #30). * RETURN VALUES: - * -1: Fatal error encoding the type. - * >=0: Number of bytes serialized. + * -1: Fatal error encoding the type. + * >0: Number of bytes serialized. */ ssize_t oer_open_type_put(const struct asn_TYPE_descriptor_s *td, const asn_oer_constraints_t *constraints, diff --git a/tests/tests-randomized/Makefile.am b/tests/tests-randomized/Makefile.am index d28968a0..923f2944 100644 --- a/tests/tests-randomized/Makefile.am +++ b/tests/tests-randomized/Makefile.am @@ -40,6 +40,7 @@ TESTS += bundles/12-UniversalString-bundle.txt TESTS += bundles/13-UTCTime-bundle.txt TESTS += bundles/14-GeneralizedTime-bundle.txt TESTS += bundles/15-CHOICE-bundle.txt +TESTS += bundles/16-SEQUENCE-bundle.txt EXTRA_DIST = \ random-test-driver.c \ diff --git a/tests/tests-randomized/bundles/16-SEQUENCE-bundle.txt b/tests/tests-randomized/bundles/16-SEQUENCE-bundle.txt new file mode 100644 index 00000000..cee78403 --- /dev/null +++ b/tests/tests-randomized/bundles/16-SEQUENCE-bundle.txt @@ -0,0 +1,69 @@ +SEQUENCE { } +SEQUENCE { ... } +SEQUENCE { null NULL } +SEQUENCE { null NULL OPTIONAL } +SEQUENCE { ..., null NULL } +SEQUENCE { ..., null NULL OPTIONAL } +SEQUENCE { ..., null BOOLEAN } +SEQUENCE { ..., null BOOLEAN DEFAULT FALSE } +SEQUENCE { ..., null BOOLEAN DEFAULT TRUE } + +SEQUENCE { null NULL } +SEQUENCE { null NULL, ... } +SEQUENCE { one NULL, two [2] NULL } +SEQUENCE { one [1] NULL, two [2] NULL } +SEQUENCE { one [2] NULL, two [1] NULL } +SEQUENCE { one [1] NULL, two [3] NULL } +SEQUENCE { one [3] NULL, two [1] NULL } +SEQUENCE { one [3] NULL, two [1] NULL, three [2] NULL } +SEQUENCE { one [4] NULL, two [3] NULL, three [1] NULL, four [2] NULL } +SEQUENCE { one [5] NULL, two [4] NULL, ..., three [3] NULL, four [2] NULL } +SEQUENCE { null NULL, ..., one [5] NULL, two [4] NULL, three [3] NULL, four [2] NULL } +SEQUENCE { one NULL, two [2] NULL, ... } +SEQUENCE { one NULL, ..., two [2] NULL } +SEQUENCE { one NULL, two [2] NULL, ..., three [3] NULL } +SEQUENCE { one NULL, ..., two [2] NULL, three [3] NULL } +SEQUENCE { one BOOLEAN, ..., two [2] BOOLEAN, three [3] BOOLEAN } +SEQUENCE { one BOOLEAN, two BIT STRING (SIZE(1..3)) } +SEQUENCE { null NULL, ..., one BOOLEAN, two BIT STRING (SIZE(1..3)) } +SEQUENCE { one NULL, two BOOLEAN, three BIT STRING (SIZE(1..3)) } +SEQUENCE { null NULL, ..., one [1] NULL, two BOOLEAN, three BIT STRING (SIZE(1..3)) } + +SEQUENCE { one NULL, ..., two [2] NULL } +SEQUENCE { one [1] NULL, ..., two [2] NULL } +SEQUENCE { one [2] NULL, ..., two [1] NULL } +SEQUENCE { one [1] NULL, ..., two [3] NULL } +SEQUENCE { one [3] NULL, ..., two [1] NULL } +SEQUENCE { one [3] NULL, ..., two [1] NULL, three [2] NULL } +SEQUENCE { one [4] NULL, ..., two [3] NULL, three [1] NULL, four [2] NULL } +SEQUENCE { one [5] NULL, ..., two [4] NULL, ..., three [3] NULL, four [2] NULL } +SEQUENCE { one NULL, ..., two [2] NULL, ... } +SEQUENCE { one NULL, ..., two [2] NULL, ..., three [3] NULL } +SEQUENCE { one NULL, ..., two [2] NULL, three [3] NULL } +SEQUENCE { one BOOLEAN, ..., two [2] BOOLEAN, three [3] BOOLEAN, ... } +SEQUENCE { one BOOLEAN, ..., two BIT STRING (SIZE(1..3)) } +SEQUENCE { null NULL, ..., one BOOLEAN, two BIT STRING (SIZE(1..3)), ... } +SEQUENCE { one NULL, ..., two BOOLEAN, three BIT STRING (SIZE(1..3)) } +SEQUENCE { null NULL, ..., one [1] NULL, two BOOLEAN, three BIT STRING (SIZE(1..3)), ... } +SEQUENCE { null NULL, ..., one [1] NULL, two BOOLEAN, three BIT STRING (SIZE(1..3)), ..., four IA5String (SIZE(0)) } + +SEQUENCE { ..., null NULL } +SEQUENCE { ..., null NULL, ... } +SEQUENCE { ..., one NULL, two [2] NULL } +SEQUENCE { ..., one [1] NULL, two [2] NULL } +SEQUENCE { ..., one [2] NULL, two [1] NULL } +SEQUENCE { ..., one [1] NULL, two [3] NULL } +SEQUENCE { ..., one [3] NULL, two [1] NULL } +SEQUENCE { ..., one [3] NULL, two [1] NULL, three [2] NULL } +SEQUENCE { ..., one [4] NULL, two [3] NULL, three [1] NULL, four [2] NULL } +SEQUENCE { ..., one [5] NULL, two [4] NULL, ..., three [3] NULL, four [2] NULL } +SEQUENCE { ..., null NULL, ..., one [5] NULL, two [4] NULL, three [3] NULL, four [2] NULL } +SEQUENCE { ..., one NULL, two [2] NULL, ... } +SEQUENCE { ..., one NULL, ..., two [2] NULL } +SEQUENCE { ..., one NULL, two [2] NULL, ..., three [3] NULL } +SEQUENCE { ..., one NULL, ..., two [2] NULL, three [3] NULL } +SEQUENCE { ..., one BOOLEAN, ..., two [2] BOOLEAN, three [3] BOOLEAN } +SEQUENCE { ..., one BOOLEAN, two BIT STRING (SIZE(1..3)) } +SEQUENCE { ..., null NULL, ..., one BOOLEAN, two BIT STRING (SIZE(1..3)) } +SEQUENCE { ..., one NULL, two BOOLEAN, three BIT STRING (SIZE(1..3)) } +SEQUENCE { ..., null NULL, ..., one [1] NULL, two BOOLEAN, three BIT STRING (SIZE(1..3)) } |