From 79b08d5af5a0b39b5f9dd78e821916ee5a7e9a61 Mon Sep 17 00:00:00 2001 From: vlm Date: Thu, 1 Jul 2004 00:52:50 +0000 Subject: [PATCH] extensibility check git-svn-id: https://asn1c.svn.sourceforge.net/svnroot/asn1c/trunk@52 59561ff5-6e30-0410-9f3c-9617f08c8826 --- ChangeLog | 6 + configure | 2 +- configure.in | 2 +- libasn1compiler/asn1c_C.c | 18 ++- tests/47-set-ext-OK.asn1 | 19 +++ tests/47-set-ext-OK.asn1.-P | 312 ++++++++++++++++++++++++++++++++++++ 6 files changed, 353 insertions(+), 6 deletions(-) create mode 100644 tests/47-set-ext-OK.asn1 create mode 100644 tests/47-set-ext-OK.asn1.-P diff --git a/ChangeLog b/ChangeLog index e5d2dba1..e9013d38 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,10 @@ +0.8.14: 2004-Jun-30 + + * Fixed compiler: extensibility of CHOICE and SET type has not been + taken into account during table construction. + (Test case 47) (Severity: high, Security impact: low) + 0.8.13: 2004-Jun-29 * Fixed compiler: the skip values for IMPLICIT tagging were broken diff --git a/configure b/configure index c76a71a6..25923f16 100755 --- a/configure +++ b/configure @@ -1881,7 +1881,7 @@ fi # Define the identity of the package. PACKAGE=asn1c - VERSION=0.8.13 + VERSION=0.8.14 cat >>confdefs.h <<_ACEOF diff --git a/configure.in b/configure.in index 982e9d6f..925750a6 100644 --- a/configure.in +++ b/configure.in @@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script. AC_INIT(libasn1parser/asn1p_y.y) AC_CANONICAL_SYSTEM AC_PREREQ(2.53) -AM_INIT_AUTOMAKE(asn1c, 0.8.13) +AM_INIT_AUTOMAKE(asn1c, 0.8.14) AC_SUBST(PATH) diff --git a/libasn1compiler/asn1c_C.c b/libasn1compiler/asn1c_C.c index bf66fe4c..d561e029 100644 --- a/libasn1compiler/asn1c_C.c +++ b/libasn1compiler/asn1c_C.c @@ -22,6 +22,7 @@ static int asn1c_lang_C_type_SET_def(arg_t *arg); static int asn1c_lang_C_type_CHOICE_def(arg_t *arg); static int asn1c_lang_C_type_SEx_OF_def(arg_t *arg, int seq_of); static int _print_tag(arg_t *arg, asn1p_expr_t *expr, struct asn1p_type_tag_s *tag_p); +static int check_if_extensible(asn1p_expr_t *expr); static int emit_tags_vector(arg_t *arg, asn1p_expr_t *expr, int*tags_impl_skip); static int emit_tag2member_map(arg_t *arg, tag2el_t *tag2el, int tag2el_count); static int emit_constraint_checking_code(arg_t *arg); @@ -400,7 +401,6 @@ asn1c_lang_C_type_SET_def(arg_t *arg) { int elements; int tags_impl_skip = 0; int comp_mode = 0; /* {root,ext=1,root,root,...} */ - int extensible = 0; tag2el_t *tag2el = NULL; int tag2el_count = 0; char *p; @@ -518,7 +518,8 @@ asn1c_lang_C_type_SET_def(arg_t *arg) { OUT("%d,\t/* Elements count */\n", elements); OUT("asn1_DEF_%s_tag2el,\n", p); OUT("%d,\t/* Count of tags in the map */\n", tag2el_count); - OUT("%d,\t/* Whether extensible */\n", extensible); + OUT("%d,\t/* Whether extensible */\n", + check_if_extensible(expr)); OUT("(unsigned int *)asn1_DEF_%s_mmap\t/* Mandatory elements map */\n", p); ); OUT("};\n"); @@ -720,7 +721,6 @@ asn1c_lang_C_type_CHOICE_def(arg_t *arg) { int elements; /* Number of elements */ int tags_impl_skip = 0; int comp_mode = 0; /* {root,ext=1,root,root,...} */ - int extensible = 0; tag2el_t *tag2el = NULL; int tag2el_count = 0; char *p; @@ -821,7 +821,8 @@ asn1c_lang_C_type_CHOICE_def(arg_t *arg) { OUT("%d,\t/* Elements count */\n", elements); OUT("asn1_DEF_%s_tag2el,\n", p); OUT("%d,\t/* Count of tags in the map */\n", tag2el_count); - OUT("%d\t/* Whether extensible */\n", extensible); + OUT("%d\t/* Whether extensible */\n", + check_if_extensible(expr)); ); OUT("};\n"); OUT("asn1_TYPE_descriptor_t asn1_DEF_%s = {\n", p); @@ -1082,6 +1083,14 @@ asn1c_lang_C_type_EXTENSIBLE(arg_t *arg) { return 0; } +static int check_if_extensible(asn1p_expr_t *expr) { + asn1p_expr_t *v; + TQ_FOR(v, &(expr->members), next) { + if(v->expr_type == A1TC_EXTENSIBLE) return 1; + } + return 0; +} + static int _print_tag(arg_t *arg, asn1p_expr_t *expr, struct asn1p_type_tag_s *tag_p) { struct asn1p_type_tag_s tag; @@ -1996,3 +2005,4 @@ _find_terminal_type(arg_t *arg) { if(expr) return expr->expr_type; return A1TC_INVALID; } + diff --git a/tests/47-set-ext-OK.asn1 b/tests/47-set-ext-OK.asn1 new file mode 100644 index 00000000..52afef11 --- /dev/null +++ b/tests/47-set-ext-OK.asn1 @@ -0,0 +1,19 @@ + +-- OK: Everything is fine + +-- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1) +-- .spelio.software.asn1c.test (9363.1.5.1) +-- .47 + +ModuleSetChoiceExtensibility + { iso org(3) dod(6) internet (1) private(4) enterprise(1) + spelio(9363) software(1) asn1c(5) test(1) 47 } + DEFINITIONS IMPLICIT TAGS EXTENSIBILITY IMPLIED ::= +BEGIN + + T1 ::= SET { i INTEGER } + T2 ::= SET { i INTEGER, ... } + T3 ::= CHOICE { i INTEGER } + T4 ::= CHOICE { i INTEGER, ... } + +END diff --git a/tests/47-set-ext-OK.asn1.-P b/tests/47-set-ext-OK.asn1.-P new file mode 100644 index 00000000..69a7dedb --- /dev/null +++ b/tests/47-set-ext-OK.asn1.-P @@ -0,0 +1,312 @@ + +/*** <<< DEPS [T1] >>> ***/ + +/* Dependencies for T1 */ +#include + + +/* + * Method of determining the components presence + */ +enum T1_PR_e { + T1_PR_i, /* Member i is present */ +}; +#include + +extern asn1_TYPE_descriptor_t asn1_DEF_T1; + +/*** <<< TYPE-DECLS [T1] >>> ***/ + + +typedef struct T1 { + INTEGER_t i; + /* + * This type is extensible, + * possible extensions are below. + */ + + /* Presence bitmask: ASN_SET_ISPRESENT(pT1, T1_PR_x) */ + unsigned int _presence_map + [((1+(8*sizeof(unsigned int))-1)/(8*sizeof(unsigned int)))]; + + /* Context for parsing across buffer boundaries */ + ber_dec_ctx_t _ber_dec_ctx; +} T1_t; + +/*** <<< STAT-DEFS [T1] >>> ***/ + +#include + +static asn1_SET_element_t asn1_DEF_T1_elements[] = { + { offsetof(struct T1, i), 0, + (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), + 0, + (void *)&asn1_DEF_INTEGER, + "i" + }, +}; +static ber_tlv_tag_t asn1_DEF_T1_tags[] = { + (ASN_TAG_CLASS_UNIVERSAL | (17 << 2)) +}; +static asn1_TYPE_tag2member_t asn1_DEF_T1_tag2el[] = { + { (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 0, 0, 0 }, /* i at 14 */ +}; +static uint8_t asn1_DEF_T1_mmap[(1 + (8 * sizeof(unsigned int)) - 1) / 8] = { + (1 << 7) +}; +static asn1_SET_specifics_t asn1_DEF_T1_specs = { + sizeof(struct T1), + offsetof(struct T1, _ber_dec_ctx), + offsetof(struct T1, _presence_map), + asn1_DEF_T1_elements, + 1, /* Elements count */ + asn1_DEF_T1_tag2el, + 1, /* Count of tags in the map */ + 1, /* Whether extensible */ + (unsigned int *)asn1_DEF_T1_mmap /* Mandatory elements map */ +}; +asn1_TYPE_descriptor_t asn1_DEF_T1 = { + "T1", + SET_constraint, + SET_decode_ber, + SET_encode_der, + SET_print, + SET_free, + 0, /* Use generic outmost tag fetcher */ + asn1_DEF_T1_tags, + sizeof(asn1_DEF_T1_tags) + /sizeof(asn1_DEF_T1_tags[0]), + 1, /* Tags to skip */ + 1, /* Whether CONSTRUCTED */ + &asn1_DEF_T1_specs /* Additional specs */ +}; + + +/*** <<< DEPS [T2] >>> ***/ + +/* Dependencies for T2 */ +#include + + +/* + * Method of determining the components presence + */ +enum T2_PR_e { + T2_PR_i, /* Member i is present */ +}; +#include + +extern asn1_TYPE_descriptor_t asn1_DEF_T2; + +/*** <<< TYPE-DECLS [T2] >>> ***/ + + +typedef struct T2 { + INTEGER_t i; + /* + * This type is extensible, + * possible extensions are below. + */ + + /* Presence bitmask: ASN_SET_ISPRESENT(pT2, T2_PR_x) */ + unsigned int _presence_map + [((1+(8*sizeof(unsigned int))-1)/(8*sizeof(unsigned int)))]; + + /* Context for parsing across buffer boundaries */ + ber_dec_ctx_t _ber_dec_ctx; +} T2_t; + +/*** <<< STAT-DEFS [T2] >>> ***/ + +#include + +static asn1_SET_element_t asn1_DEF_T2_elements[] = { + { offsetof(struct T2, i), 0, + (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), + 0, + (void *)&asn1_DEF_INTEGER, + "i" + }, +}; +static ber_tlv_tag_t asn1_DEF_T2_tags[] = { + (ASN_TAG_CLASS_UNIVERSAL | (17 << 2)) +}; +static asn1_TYPE_tag2member_t asn1_DEF_T2_tag2el[] = { + { (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 0, 0, 0 }, /* i at 15 */ +}; +static uint8_t asn1_DEF_T2_mmap[(1 + (8 * sizeof(unsigned int)) - 1) / 8] = { + (1 << 7) +}; +static asn1_SET_specifics_t asn1_DEF_T2_specs = { + sizeof(struct T2), + offsetof(struct T2, _ber_dec_ctx), + offsetof(struct T2, _presence_map), + asn1_DEF_T2_elements, + 1, /* Elements count */ + asn1_DEF_T2_tag2el, + 1, /* Count of tags in the map */ + 1, /* Whether extensible */ + (unsigned int *)asn1_DEF_T2_mmap /* Mandatory elements map */ +}; +asn1_TYPE_descriptor_t asn1_DEF_T2 = { + "T2", + SET_constraint, + SET_decode_ber, + SET_encode_der, + SET_print, + SET_free, + 0, /* Use generic outmost tag fetcher */ + asn1_DEF_T2_tags, + sizeof(asn1_DEF_T2_tags) + /sizeof(asn1_DEF_T2_tags[0]), + 1, /* Tags to skip */ + 1, /* Whether CONSTRUCTED */ + &asn1_DEF_T2_specs /* Additional specs */ +}; + + +/*** <<< DEPS [T3] >>> ***/ + +/* Dependencies for T3 */ +#include + +extern asn1_TYPE_descriptor_t asn1_DEF_T3; + +/*** <<< TYPE-DECLS [T3] >>> ***/ + + +typedef struct T3 { + enum { + T3_PR_NOTHING, /* No components present */ + T3_PR_i, + } present; + union { + INTEGER_t i; + /* + * This type is extensible, + * possible extensions are below. + */ + } choice; + + /* Context for parsing across buffer boundaries */ + ber_dec_ctx_t _ber_dec_ctx; +} T3_t; + +/*** <<< STAT-DEFS [T3] >>> ***/ + +#include + +static asn1_CHOICE_element_t asn1_DEF_T3_elements[] = { + { offsetof(struct T3, choice.i), 0, + (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), + 0, + (void *)&asn1_DEF_INTEGER, + "i" + }, +}; +static ber_tlv_tag_t asn1_DEF_T3_tags[] = { + +}; +static asn1_TYPE_tag2member_t asn1_DEF_T3_tag2el[] = { + { (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 0, 0, 0 }, /* i at 16 */ +}; +static asn1_CHOICE_specifics_t asn1_DEF_T3_specs = { + sizeof(struct T3), + offsetof(struct T3, _ber_dec_ctx), + offsetof(struct T3, present), + sizeof(((struct T3 *)0)->present), + asn1_DEF_T3_elements, + 1, /* Elements count */ + asn1_DEF_T3_tag2el, + 1, /* Count of tags in the map */ + 1 /* Whether extensible */ +}; +asn1_TYPE_descriptor_t asn1_DEF_T3 = { + "T3", + CHOICE_constraint, + CHOICE_decode_ber, + CHOICE_encode_der, + CHOICE_print, + CHOICE_free, + CHOICE_outmost_tag, + asn1_DEF_T3_tags, + sizeof(asn1_DEF_T3_tags) + /sizeof(asn1_DEF_T3_tags[0]), + 0, /* Tags to skip */ + 1, /* Whether CONSTRUCTED */ + &asn1_DEF_T3_specs /* Additional specs */ +}; + + +/*** <<< DEPS [T4] >>> ***/ + +/* Dependencies for T4 */ +#include + +extern asn1_TYPE_descriptor_t asn1_DEF_T4; + +/*** <<< TYPE-DECLS [T4] >>> ***/ + + +typedef struct T4 { + enum { + T4_PR_NOTHING, /* No components present */ + T4_PR_i, + } present; + union { + INTEGER_t i; + /* + * This type is extensible, + * possible extensions are below. + */ + } choice; + + /* Context for parsing across buffer boundaries */ + ber_dec_ctx_t _ber_dec_ctx; +} T4_t; + +/*** <<< STAT-DEFS [T4] >>> ***/ + +#include + +static asn1_CHOICE_element_t asn1_DEF_T4_elements[] = { + { offsetof(struct T4, choice.i), 0, + (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), + 0, + (void *)&asn1_DEF_INTEGER, + "i" + }, +}; +static ber_tlv_tag_t asn1_DEF_T4_tags[] = { + +}; +static asn1_TYPE_tag2member_t asn1_DEF_T4_tag2el[] = { + { (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 0, 0, 0 }, /* i at 17 */ +}; +static asn1_CHOICE_specifics_t asn1_DEF_T4_specs = { + sizeof(struct T4), + offsetof(struct T4, _ber_dec_ctx), + offsetof(struct T4, present), + sizeof(((struct T4 *)0)->present), + asn1_DEF_T4_elements, + 1, /* Elements count */ + asn1_DEF_T4_tag2el, + 1, /* Count of tags in the map */ + 1 /* Whether extensible */ +}; +asn1_TYPE_descriptor_t asn1_DEF_T4 = { + "T4", + CHOICE_constraint, + CHOICE_decode_ber, + CHOICE_encode_der, + CHOICE_print, + CHOICE_free, + CHOICE_outmost_tag, + asn1_DEF_T4_tags, + sizeof(asn1_DEF_T4_tags) + /sizeof(asn1_DEF_T4_tags[0]), + 0, /* Tags to skip */ + 1, /* Whether CONSTRUCTED */ + &asn1_DEF_T4_specs /* Additional specs */ +}; +