diff --git a/examples/sample.makefile.regen b/examples/sample.makefile.regen index b3b0e0d8..57a0daef 100755 --- a/examples/sample.makefile.regen +++ b/examples/sample.makefile.regen @@ -57,8 +57,8 @@ cat Makefile.am.sample \ echo " $0" echo echo 'check: ${TARGET}' - echo " @if test -f ./sample-${ASN1PDU}-1.[db]er ; then \\" - echo " for f in ./sample-${ASN1PDU}-*.[db]er; do \\" + echo " @if test -f sample-${ASN1PDU}-1.[db]er ; then \\" + echo " for f in sample-${ASN1PDU}-*.[db]er; do \\" echo ' echo "Recoding $$f into XER and back..."; \' echo ' ./${TARGET} -iber -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \' echo ' ./${TARGET} -iber -oxer -b 17 $$f > ./.tmp.1.$$$$ || exit 2; \' @@ -69,8 +69,8 @@ cat Makefile.am.sample \ echo ' diff ./.tmp.1.$$$$ ./.tmp.2.$$$$ || exit 2; \' echo ' rm -f ./.tmp.[12].$$$$; \' echo ' done; fi' - echo " @if test -f ./sample-${ASN1PDU}-1.xer ; then \\" - echo " for f in ./sample-${ASN1PDU}-*.xer; do \\" + echo " @if test -f sample-${ASN1PDU}-1.xer ; then \\" + echo " for f in sample-${ASN1PDU}-*.xer; do \\" echo ' echo "Recoding $$f into DER and back..."; \' echo ' ./${TARGET} -ixer -oder -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \' echo ' ./${TARGET} -ixer -oder -b 17 $$f > ./.tmp.1.$$$$ || exit 2; \' @@ -81,8 +81,8 @@ cat Makefile.am.sample \ echo ' diff $$f ./.tmp.2.$$$$ || exit 2; \' echo ' rm -f ./.tmp.[12].$$$$; \' echo ' done; fi' - echo " @if test -f ./sample-${ASN1PDU}-1.per ; then \\" - echo " for f in ./sample-${ASN1PDU}-[1-9].per; do \\" + echo " @if test -f sample-${ASN1PDU}-1.per ; then \\" + echo " for f in sample-${ASN1PDU}-[1-9].per; do \\" echo ' echo "Recoding $$f into DER into XER and back..."; \' echo ' ./${TARGET} -iper -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \' echo ' ./${TARGET} -iper -oxer -b 17 $$f > ./.tmp.2.$$$$ || exit 2; \' @@ -97,19 +97,20 @@ cat Makefile.am.sample \ echo ' diff ./.tmp.1.$$$$ ./.tmp.3.$$$$ || exit 2; \' echo ' rm -f ./.tmp.[1234].$$$$; \' echo ' done; fi' - echo " @if test -f ./sample-${ASN1PDU}-1-padded.per ; then \\" - echo " for f in ./sample-${ASN1PDU}-[1-9]-padded.per; do \\" + echo " @if test -f sample-${ASN1PDU}-1-padded.per ; then \\" + echo " for f in sample-*-[1-9]-padded.per; do \\" + echo ' pdu=`echo $$f | sed -E -e "s/sample-([A-Za-z-]+)-[0-9].*/\1/"`; \' echo ' echo "Recoding byte-padded $$f into DER into XER and back..."; \' - echo ' ./${TARGET} -per-padded -iper -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \' - echo ' ./${TARGET} -per-padded -iper -oxer -b 17 $$f > ./.tmp.2.$$$$ || exit 2; \' - echo ' ./${TARGET} -per-padded -iper -oxer -b 33 $$f > ./.tmp.3.$$$$ || exit 2; \' - echo ' ./${TARGET} -per-padded -iper -oxer -b 980 $$f > ./.tmp.4.$$$$ || exit 2; \' + echo ' ./${TARGET} -per-padded -p $$pdu -iper -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \' + echo ' ./${TARGET} -per-padded -p $$pdu -iper -oxer -b 17 $$f > ./.tmp.2.$$$$ || exit 2; \' + echo ' ./${TARGET} -per-padded -p $$pdu -iper -oxer -b 33 $$f > ./.tmp.3.$$$$ || exit 2; \' + echo ' ./${TARGET} -per-padded -p $$pdu -iper -oxer -b 980 $$f > ./.tmp.4.$$$$ || exit 2; \' echo ' diff ./.tmp.1.$$$$ ./.tmp.2.$$$$ || exit 2; \' echo ' diff ./.tmp.2.$$$$ ./.tmp.3.$$$$ || exit 2; \' echo ' diff ./.tmp.3.$$$$ ./.tmp.4.$$$$ || exit 2; \' - echo ' ./${TARGET} -per-padded -iper -oder $$f > ./.tmp.1.$$$$ || exit 2; \' - echo ' ./${TARGET} -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \' - echo ' ./${TARGET} -ixer -oper ./.tmp.2.$$$$ > ./.tmp.1.$$$$ || exit 2; \' + echo ' ./${TARGET} -per-padded -p $$pdu -iper -oder $$f > ./.tmp.1.$$$$ || exit 2; \' + echo ' ./${TARGET} -p $$pdu -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \' + echo ' ./${TARGET} -p $$pdu -ixer -oper ./.tmp.2.$$$$ > ./.tmp.1.$$$$ || exit 2; \' echo ' diff $$f ./.tmp.1.$$$$ || exit 2; \' echo ' rm -f ./.tmp.[1234].$$$$; \' echo ' done; fi' diff --git a/examples/sample.source.LDAP3/Makefile b/examples/sample.source.LDAP3/Makefile index 6de7245e..86a7917a 100644 --- a/examples/sample.source.LDAP3/Makefile +++ b/examples/sample.source.LDAP3/Makefile @@ -200,8 +200,8 @@ regen-makefile: ../sample.makefile.regen check: ${TARGET} - @if test -f ./sample-LDAPMessage-1.[db]er ; then \ - for f in ./sample-LDAPMessage-*.[db]er; do \ + @if test -f sample-LDAPMessage-1.[db]er ; then \ + for f in sample-LDAPMessage-*.[db]er; do \ echo "Recoding $$f into XER and back..."; \ ./${TARGET} -iber -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \ ./${TARGET} -iber -oxer -b 17 $$f > ./.tmp.1.$$$$ || exit 2; \ @@ -212,8 +212,8 @@ check: ${TARGET} diff ./.tmp.1.$$$$ ./.tmp.2.$$$$ || exit 2; \ rm -f ./.tmp.[12].$$$$; \ done; fi - @if test -f ./sample-LDAPMessage-1.xer ; then \ - for f in ./sample-LDAPMessage-*.xer; do \ + @if test -f sample-LDAPMessage-1.xer ; then \ + for f in sample-LDAPMessage-*.xer; do \ echo "Recoding $$f into DER and back..."; \ ./${TARGET} -ixer -oder -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \ ./${TARGET} -ixer -oder -b 17 $$f > ./.tmp.1.$$$$ || exit 2; \ @@ -224,8 +224,8 @@ check: ${TARGET} diff $$f ./.tmp.2.$$$$ || exit 2; \ rm -f ./.tmp.[12].$$$$; \ done; fi - @if test -f ./sample-LDAPMessage-1.per ; then \ - for f in ./sample-LDAPMessage-[1-9].per; do \ + @if test -f sample-LDAPMessage-1.per ; then \ + for f in sample-LDAPMessage-[1-9].per; do \ echo "Recoding $$f into DER into XER and back..."; \ ./${TARGET} -iper -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \ ./${TARGET} -iper -oxer -b 17 $$f > ./.tmp.2.$$$$ || exit 2; \ @@ -240,19 +240,20 @@ check: ${TARGET} diff ./.tmp.1.$$$$ ./.tmp.3.$$$$ || exit 2; \ rm -f ./.tmp.[1234].$$$$; \ done; fi - @if test -f ./sample-LDAPMessage-1-padded.per ; then \ - for f in ./sample-LDAPMessage-[1-9]-padded.per; do \ + @if test -f sample-LDAPMessage-1-padded.per ; then \ + for f in sample-*-[1-9]-padded.per; do \ + pdu=`echo $$f | sed -E -e "s/sample-([A-Za-z-]+)-[0-9].*/\1/"`; \ echo "Recoding byte-padded $$f into DER into XER and back..."; \ - ./${TARGET} -per-padded -iper -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \ - ./${TARGET} -per-padded -iper -oxer -b 17 $$f > ./.tmp.2.$$$$ || exit 2; \ - ./${TARGET} -per-padded -iper -oxer -b 33 $$f > ./.tmp.3.$$$$ || exit 2; \ - ./${TARGET} -per-padded -iper -oxer -b 980 $$f > ./.tmp.4.$$$$ || exit 2; \ + ./${TARGET} -per-padded -p $$pdu -iper -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \ + ./${TARGET} -per-padded -p $$pdu -iper -oxer -b 17 $$f > ./.tmp.2.$$$$ || exit 2; \ + ./${TARGET} -per-padded -p $$pdu -iper -oxer -b 33 $$f > ./.tmp.3.$$$$ || exit 2; \ + ./${TARGET} -per-padded -p $$pdu -iper -oxer -b 980 $$f > ./.tmp.4.$$$$ || exit 2; \ diff ./.tmp.1.$$$$ ./.tmp.2.$$$$ || exit 2; \ diff ./.tmp.2.$$$$ ./.tmp.3.$$$$ || exit 2; \ diff ./.tmp.3.$$$$ ./.tmp.4.$$$$ || exit 2; \ - ./${TARGET} -per-padded -iper -oder $$f > ./.tmp.1.$$$$ || exit 2; \ - ./${TARGET} -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \ - ./${TARGET} -ixer -oper ./.tmp.2.$$$$ > ./.tmp.1.$$$$ || exit 2; \ + ./${TARGET} -per-padded -p $$pdu -iper -oder $$f > ./.tmp.1.$$$$ || exit 2; \ + ./${TARGET} -p $$pdu -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \ + ./${TARGET} -p $$pdu -ixer -oper ./.tmp.2.$$$$ > ./.tmp.1.$$$$ || exit 2; \ diff $$f ./.tmp.1.$$$$ || exit 2; \ rm -f ./.tmp.[1234].$$$$; \ done; fi diff --git a/examples/sample.source.RRC/Makefile b/examples/sample.source.RRC/Makefile index 6e623894..313abb19 100644 --- a/examples/sample.source.RRC/Makefile +++ b/examples/sample.source.RRC/Makefile @@ -4777,8 +4777,8 @@ regen-makefile: ../sample.makefile.regen check: ${TARGET} - @if test -f ./sample-DL-DCCH-Message-1.[db]er ; then \ - for f in ./sample-DL-DCCH-Message-*.[db]er; do \ + @if test -f sample-DL-DCCH-Message-1.[db]er ; then \ + for f in sample-DL-DCCH-Message-*.[db]er; do \ echo "Recoding $$f into XER and back..."; \ ./${TARGET} -iber -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \ ./${TARGET} -iber -oxer -b 17 $$f > ./.tmp.1.$$$$ || exit 2; \ @@ -4789,8 +4789,8 @@ check: ${TARGET} diff ./.tmp.1.$$$$ ./.tmp.2.$$$$ || exit 2; \ rm -f ./.tmp.[12].$$$$; \ done; fi - @if test -f ./sample-DL-DCCH-Message-1.xer ; then \ - for f in ./sample-DL-DCCH-Message-*.xer; do \ + @if test -f sample-DL-DCCH-Message-1.xer ; then \ + for f in sample-DL-DCCH-Message-*.xer; do \ echo "Recoding $$f into DER and back..."; \ ./${TARGET} -ixer -oder -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \ ./${TARGET} -ixer -oder -b 17 $$f > ./.tmp.1.$$$$ || exit 2; \ @@ -4801,8 +4801,8 @@ check: ${TARGET} diff $$f ./.tmp.2.$$$$ || exit 2; \ rm -f ./.tmp.[12].$$$$; \ done; fi - @if test -f ./sample-DL-DCCH-Message-1.per ; then \ - for f in ./sample-DL-DCCH-Message-[1-9].per; do \ + @if test -f sample-DL-DCCH-Message-1.per ; then \ + for f in sample-DL-DCCH-Message-[1-9].per; do \ echo "Recoding $$f into DER into XER and back..."; \ ./${TARGET} -iper -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \ ./${TARGET} -iper -oxer -b 17 $$f > ./.tmp.2.$$$$ || exit 2; \ @@ -4817,20 +4817,28 @@ check: ${TARGET} diff ./.tmp.1.$$$$ ./.tmp.3.$$$$ || exit 2; \ rm -f ./.tmp.[1234].$$$$; \ done; fi - @if test -f ./sample-DL-DCCH-Message-1-padded.per ; then \ - for f in ./sample-DL-DCCH-Message-[1-9]-padded.per; do \ + @if test -f sample-DL-DCCH-Message-1-padded.per ; then \ + for f in sample-*-[1-9]-padded.per; do \ + pdu=`echo $$f | sed -E -e "s/sample-([A-Za-z-]+)-[0-9].*/\1/"`; \ echo "Recoding byte-padded $$f into DER into XER and back..."; \ - ./${TARGET} -per-padded -iper -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \ - ./${TARGET} -per-padded -iper -oxer -b 17 $$f > ./.tmp.2.$$$$ || exit 2; \ - ./${TARGET} -per-padded -iper -oxer -b 33 $$f > ./.tmp.3.$$$$ || exit 2; \ - ./${TARGET} -per-padded -iper -oxer -b 980 $$f > ./.tmp.4.$$$$ || exit 2; \ - diff ./.tmp.1.$$$$ ./.tmp.2.$$$$ || exit 1; \ + echo "./${TARGET} -per-padded -p $$pdu -iper -oxer -b 1 $$f > ./.tmp.1.$$$$"; \ + ./${TARGET} -per-padded -p $$pdu -iper -oxer -b 1 $$f > ./.tmp.1.$$$$ || exit 2; \ + echo "./${TARGET} -per-padded -p $$pdu -iper -oxer -b 17 $$f > ./.tmp.2.$$$$"; \ + ./${TARGET} -per-padded -p $$pdu -iper -oxer -b 17 $$f > ./.tmp.2.$$$$ || exit 2; \ + echo "./${TARGET} -per-padded -p $$pdu -iper -oxer -b 33 $$f > ./.tmp.3.$$$$"; \ + ./${TARGET} -per-padded -p $$pdu -iper -oxer -b 33 $$f > ./.tmp.3.$$$$ || exit 2; \ + echo "./${TARGET} -per-padded -p $$pdu -iper -oxer -b 980 $$f > ./.tmp.4.$$$$"; \ + ./${TARGET} -per-padded -p $$pdu -iper -oxer -b 980 $$f > ./.tmp.4.$$$$ || exit 2; \ + diff ./.tmp.1.$$$$ ./.tmp.2.$$$$ || exit 2; \ diff ./.tmp.2.$$$$ ./.tmp.3.$$$$ || exit 2; \ - diff ./.tmp.3.$$$$ ./.tmp.4.$$$$ || exit 3; \ - ./${TARGET} -per-padded -iper -oder $$f > ./.tmp.1.$$$$ || exit 2; \ - ./${TARGET} -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \ - ./${TARGET} -ixer -oper ./.tmp.2.$$$$ > ./.tmp.1.$$$$ || exit 2; \ - diff $$f ./.tmp.1.$$$$ || exit 4; \ + diff ./.tmp.3.$$$$ ./.tmp.4.$$$$ || exit 2; \ + echo "./${TARGET} -per-padded -p $$pdu -iper -oder $$f > ./.tmp.1.$$$$"; \ + ./${TARGET} -per-padded -p $$pdu -iper -oder $$f > ./.tmp.1.$$$$ || exit 2; \ + echo "./${TARGET} -p $$pdu -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$"; \ + ./${TARGET} -p $$pdu -iber -oxer ./.tmp.1.$$$$ > ./.tmp.2.$$$$ || exit 2; \ + echo "./${TARGET} -p $$pdu -ixer -oper ./.tmp.2.$$$$ > ./.tmp.1.$$$$"; \ + ./${TARGET} -p $$pdu -ixer -oper ./.tmp.2.$$$$ > ./.tmp.1.$$$$ || exit 2; \ + diff $$f ./.tmp.1.$$$$ || exit 2; \ rm -f ./.tmp.[1234].$$$$; \ done; fi @echo ================ diff --git a/examples/sample.source.RRC/sample-BCCH-BCH-Message-2-padded.per b/examples/sample.source.RRC/sample-BCCH-BCH-Message-2-padded.per new file mode 100644 index 00000000..0d6babcd Binary files /dev/null and b/examples/sample.source.RRC/sample-BCCH-BCH-Message-2-padded.per differ diff --git a/skeletons/OCTET_STRING.c b/skeletons/OCTET_STRING.c index 3bef5608..3a83bd98 100644 --- a/skeletons/OCTET_STRING.c +++ b/skeletons/OCTET_STRING.c @@ -1328,8 +1328,11 @@ OCTET_STRING_encode_uper(asn_TYPE_descriptor_t *td, sizeinunits = sizeinunits * 8 - (st->bits_unused & 0x07); } - ASN_DEBUG("Encoding %s into %d units of %d bits", - td->name, sizeinunits, unit_bits); + ASN_DEBUG("Encoding %s into %d units of %d bits" + " (%d..%d, effective %d)%s", + td->name, sizeinunits, unit_bits, + ct->lower_bound, ct->upper_bound, + ct->effective_bits, ct_extensible ? " EXT" : ""); /* Figure out wheter size lies within PER visible consrtaint */ diff --git a/skeletons/asn_codecs.h b/skeletons/asn_codecs.h index 1ee73776..4a251d94 100644 --- a/skeletons/asn_codecs.h +++ b/skeletons/asn_codecs.h @@ -62,6 +62,7 @@ typedef struct asn_enc_rval_s { tmp_error.encoded = -1; \ tmp_error.failed_type = td; \ tmp_error.structure_ptr = sptr; \ + ASN_DEBUG("Failed to encode element %s", td->name); \ return tmp_error; \ } while(0) #define _ASN_ENCODED_OK(rval) do { \ @@ -91,6 +92,7 @@ typedef struct asn_dec_rval_s { asn_dec_rval_t tmp_error; \ tmp_error.code = RC_FAIL; \ tmp_error.consumed = 0; \ + ASN_DEBUG("Failed to decode element %s", td->name); \ return tmp_error; \ } while(0) #define _ASN_DECODE_STARVED do { \ diff --git a/skeletons/asn_codecs_prim.c b/skeletons/asn_codecs_prim.c index 97dc22af..4e5c6393 100644 --- a/skeletons/asn_codecs_prim.c +++ b/skeletons/asn_codecs_prim.c @@ -22,11 +22,7 @@ ber_decode_primitive(asn_codec_ctx_t *opt_codec_ctx, */ if(st == NULL) { st = (ASN__PRIMITIVE_TYPE_t *)CALLOC(1, sizeof(*st)); - if(st == NULL) { - rval.code = RC_FAIL; - rval.consumed = 0; - return rval; - } + if(st == NULL) _ASN_DECODE_FAILED; *sptr = (void *)st; } @@ -59,17 +55,13 @@ ber_decode_primitive(asn_codec_ctx_t *opt_codec_ctx, if(sizeof(st->size) != sizeof(length) && (ber_tlv_len_t)st->size != length) { st->size = 0; - rval.code = RC_FAIL; - rval.consumed = 0; - return rval; + _ASN_DECODE_FAILED; } st->buf = (uint8_t *)MALLOC(length + 1); if(!st->buf) { st->size = 0; - rval.code = RC_FAIL; - rval.consumed = 0; - return rval; + _ASN_DECODE_FAILED; } memcpy(st->buf, buf_ptr, length); @@ -249,12 +241,7 @@ xer_decode_primitive(asn_codec_ctx_t *opt_codec_ctx, */ if(!*sptr) { *sptr = CALLOC(1, struct_size); - if(!*sptr) { - asn_dec_rval_t rval; - rval.code = RC_FAIL; - rval.consumed = 0; - return rval; - } + if(!*sptr) _ASN_DECODE_FAILED; } memset(&s_ctx, 0, sizeof(s_ctx)); @@ -284,8 +271,7 @@ xer_decode_primitive(asn_codec_ctx_t *opt_codec_ctx, /* * This decoder does not like empty stuff. */ - rc.code = RC_FAIL; - rc.consumed = 0; + _ASN_DECODE_FAILED; } } break; @@ -300,6 +286,8 @@ xer_decode_primitive(asn_codec_ctx_t *opt_codec_ctx, rc.consumed = 0; if(s_arg.want_more) rc.code = RC_WMORE; + else + _ASN_DECODE_FAILED; break; } return rc; diff --git a/skeletons/converter-sample.c b/skeletons/converter-sample.c index 7ed49df8..1013e653 100644 --- a/skeletons/converter-sample.c +++ b/skeletons/converter-sample.c @@ -665,8 +665,10 @@ data_decode_from_file(asn_TYPE_descriptor_t *pduType, FILE *file, const char *na * Print a message and return failure only if not EOF, * unless this is our first PDU (empty file). */ - if((on_first_pdu || new_offset != old_offset || DynamicBuffer.length) - && (iform != INP_XER || on_first_pdu)) { + if(on_first_pdu + || DynamicBuffer.length + || new_offset - old_offset > ((iform == INP_XER)?sizeof("\r\n")-1:0) + ) { DEBUG("ofp %d, no=%ld, oo=%ld, dbl=%ld", on_first_pdu, (long)new_offset, (long)old_offset, (long)DynamicBuffer.length); diff --git a/skeletons/xer_decoder.c b/skeletons/xer_decoder.c index 2b3f16a6..161dc78c 100644 --- a/skeletons/xer_decoder.c +++ b/skeletons/xer_decoder.c @@ -173,6 +173,8 @@ xer_check_tag(const void *buf_ptr, int size, const char *need_tag) { #define RETURN(_code) do { \ rval.code = _code; \ rval.consumed = consumed_myself; \ + if(rval.code != RC_OK) \ + ASN_DEBUG("Failed with %d", rval.code); \ return rval; \ } while(0)