diff options
Diffstat (limited to 'lib/ASN1.y')
-rw-r--r-- | lib/ASN1.y | 189 |
1 files changed, 109 insertions, 80 deletions
@@ -32,6 +32,7 @@ #include <structure.h> #include <libtasn1.h> +static list_type *e_list = NULL; static FILE *file_asn1; /* Pointer to file to parse */ static int result_parse = 0; /* result of the parser algorithm */ @@ -52,6 +53,15 @@ static const char *file_name; /* file to parse */ static void _asn1_yyerror (const char *); static int _asn1_yylex(void); +#define SAFE_COPY(dst, dst_size, fmt, ...) { \ + int _ret = snprintf(dst, dst_size, fmt, __VA_ARGS__); \ + if (_ret != (int)strlen(dst)) \ + { \ + fprintf(stderr, "%s:%u: Oversize value\n", \ + file_name, line_number); \ + exit(1); \ + } \ +} %} /* Prefix symbols and functions with _asn1_ */ @@ -135,7 +145,7 @@ static int _asn1_yylex(void); definitions: definitions_id DEFINITIONS explicit_implicit TAGS "::=" BEGIN /* imports_def */ type_constant_list END - {$$=_asn1_add_static_node(ASN1_ETYPE_DEFINITIONS|$3); + {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_DEFINITIONS|$3); _asn1_set_name($$,_asn1_get_name($1)); _asn1_set_name($1,""); _asn1_set_right($1,$7); @@ -149,7 +159,7 @@ pos_num : NUM {snprintf($$,sizeof($$),"%s",$1);} | '+' NUM {snprintf($$,sizeof($$),"%s",$2);} ; -neg_num : '-' NUM {snprintf($$,sizeof($$),"-%s",$2);} +neg_num : '-' NUM {SAFE_COPY($$,sizeof($$),"-%s",$2);} ; pos_neg_num : pos_num {snprintf($$,sizeof($$),"%s",$1);} @@ -161,7 +171,7 @@ num_identifier : NUM {snprintf($$,sizeof($$),"%s",$1);} ; int_identifier : NUM {snprintf($$,sizeof($$),"%s",$1);} - | '-' NUM {snprintf($$,sizeof($$),"-%s",$2);} + | '-' NUM {SAFE_COPY($$,sizeof($$),"-%s",$2);} | IDENTIFIER {snprintf($$,sizeof($$),"%s",$1);} ; @@ -169,9 +179,9 @@ pos_neg_identifier : pos_neg_num {snprintf($$,sizeof($$),"%s",$1);} | IDENTIFIER {snprintf($$,sizeof($$),"%s",$1);} ; -constant: '(' pos_neg_num ')' {$$=_asn1_add_static_node(ASN1_ETYPE_CONSTANT); +constant: '(' pos_neg_num ')' {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_CONSTANT); _asn1_set_value($$,$2,strlen($2)+1);} - | IDENTIFIER'('pos_neg_num')' {$$=_asn1_add_static_node(ASN1_ETYPE_CONSTANT); + | IDENTIFIER'('pos_neg_num')' {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_CONSTANT); _asn1_set_name($$,$1); _asn1_set_value($$,$3,strlen($3)+1);} ; @@ -181,9 +191,9 @@ constant_list: constant {$$=$1;} _asn1_set_right(_asn1_get_last_right($1),$3);} ; -obj_constant: num_identifier {$$=_asn1_add_static_node(ASN1_ETYPE_CONSTANT); +obj_constant: num_identifier {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_CONSTANT); _asn1_set_value($$,$1,strlen($1)+1);} - | IDENTIFIER'('NUM')' {$$=_asn1_add_static_node(ASN1_ETYPE_CONSTANT); + | IDENTIFIER'('NUM')' {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_CONSTANT); _asn1_set_name($$,$1); _asn1_set_value($$,$3,strlen($3)+1);} ; @@ -198,9 +208,9 @@ class : UNIVERSAL {$$=CONST_UNIVERSAL;} | APPLICATION {$$=CONST_APPLICATION;} ; -tag_type : '[' NUM ']' {$$=_asn1_add_static_node(ASN1_ETYPE_TAG); +tag_type : '[' NUM ']' {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_TAG); _asn1_set_value($$,$2,strlen($2)+1);} - | '[' class NUM ']' {$$=_asn1_add_static_node(ASN1_ETYPE_TAG | $2); + | '[' class NUM ']' {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_TAG | $2); _asn1_set_value($$,$3,strlen($3)+1);} ; @@ -209,10 +219,10 @@ tag : tag_type {$$=$1;} | tag_type IMPLICIT {$$=_asn1_mod_type($1,CONST_IMPLICIT);} ; -default : DEFAULT pos_neg_identifier {$$=_asn1_add_static_node(ASN1_ETYPE_DEFAULT); +default : DEFAULT pos_neg_identifier {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_DEFAULT); _asn1_set_value($$,$2,strlen($2)+1);} - | DEFAULT ASN1_TRUE {$$=_asn1_add_static_node(ASN1_ETYPE_DEFAULT|CONST_TRUE);} - | DEFAULT ASN1_FALSE {$$=_asn1_add_static_node(ASN1_ETYPE_DEFAULT|CONST_FALSE);} + | DEFAULT ASN1_TRUE {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_DEFAULT|CONST_TRUE);} + | DEFAULT ASN1_FALSE {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_DEFAULT|CONST_FALSE);} ; @@ -221,28 +231,28 @@ pos_neg_list: pos_neg_num ; -integer_def: INTEGER {$$=_asn1_add_static_node(ASN1_ETYPE_INTEGER);} - | INTEGER'{'constant_list'}' {$$=_asn1_add_static_node(ASN1_ETYPE_INTEGER|CONST_LIST); +integer_def: INTEGER {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_INTEGER);} + | INTEGER'{'constant_list'}' {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_INTEGER|CONST_LIST); _asn1_set_down($$,$3);} - | integer_def'(' pos_neg_list ')' {$$=_asn1_add_static_node(ASN1_ETYPE_INTEGER);} + | integer_def'(' pos_neg_list ')' {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_INTEGER);} | integer_def'('int_identifier'.''.'int_identifier')' - {$$=_asn1_add_static_node(ASN1_ETYPE_INTEGER|CONST_MIN_MAX); - _asn1_set_down($$,_asn1_add_static_node(ASN1_ETYPE_SIZE)); + {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_INTEGER|CONST_MIN_MAX); + _asn1_set_down($$,_asn1_add_static_node(&e_list, ASN1_ETYPE_SIZE)); _asn1_set_value(_asn1_get_down($$),$6,strlen($6)+1); _asn1_set_name(_asn1_get_down($$),$3);} ; -boolean_def: BOOLEAN {$$=_asn1_add_static_node(ASN1_ETYPE_BOOLEAN);} +boolean_def: BOOLEAN {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_BOOLEAN);} ; -Time: UTCTime {$$=_asn1_add_static_node(ASN1_ETYPE_UTC_TIME);} - | GeneralizedTime {$$=_asn1_add_static_node(ASN1_ETYPE_GENERALIZED_TIME);} +Time: UTCTime {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_UTC_TIME);} + | GeneralizedTime {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_GENERALIZED_TIME);} ; -size_def2: SIZE'('num_identifier')' {$$=_asn1_add_static_node(ASN1_ETYPE_SIZE|CONST_1_PARAM); +size_def2: SIZE'('num_identifier')' {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_SIZE|CONST_1_PARAM); _asn1_set_value($$,$3,strlen($3)+1);} | SIZE'('num_identifier'.''.'num_identifier')' - {$$=_asn1_add_static_node(ASN1_ETYPE_SIZE|CONST_MIN_MAX); + {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_SIZE|CONST_MIN_MAX); _asn1_set_value($$,$3,strlen($3)+1); _asn1_set_name($$,$6);} ; @@ -251,57 +261,57 @@ size_def: size_def2 {$$=$1;} | '(' size_def2 ')' {$$=$2;} ; -generalstring_def: GeneralString {$$=_asn1_add_static_node(ASN1_ETYPE_GENERALSTRING);} - | GeneralString size_def {$$=_asn1_add_static_node(ASN1_ETYPE_GENERALSTRING|CONST_SIZE); +generalstring_def: GeneralString {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_GENERALSTRING);} + | GeneralString size_def {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_GENERALSTRING|CONST_SIZE); _asn1_set_down($$,$2);} ; -numericstring_def: NumericString {$$=_asn1_add_static_node(ASN1_ETYPE_NUMERIC_STRING|CONST_UNIVERSAL);} - | NumericString size_def {$$=_asn1_add_static_node(ASN1_ETYPE_NUMERIC_STRING|CONST_SIZE); +numericstring_def: NumericString {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_NUMERIC_STRING|CONST_UNIVERSAL);} + | NumericString size_def {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_NUMERIC_STRING|CONST_SIZE); _asn1_set_down($$,$2);} ; -ia5string_def: IA5String {$$=_asn1_add_static_node(ASN1_ETYPE_IA5_STRING);} - | IA5String size_def {$$=_asn1_add_static_node(ASN1_ETYPE_IA5_STRING|CONST_SIZE); +ia5string_def: IA5String {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_IA5_STRING);} + | IA5String size_def {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_IA5_STRING|CONST_SIZE); _asn1_set_down($$,$2);} ; -teletexstring_def: TeletexString {$$=_asn1_add_static_node(ASN1_ETYPE_TELETEX_STRING);} - | TeletexString size_def {$$=_asn1_add_static_node(ASN1_ETYPE_TELETEX_STRING|CONST_SIZE); +teletexstring_def: TeletexString {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_TELETEX_STRING);} + | TeletexString size_def {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_TELETEX_STRING|CONST_SIZE); _asn1_set_down($$,$2);} ; -printablestring_def: PrintableString {$$=_asn1_add_static_node(ASN1_ETYPE_PRINTABLE_STRING);} - | PrintableString size_def {$$=_asn1_add_static_node(ASN1_ETYPE_PRINTABLE_STRING|CONST_SIZE); +printablestring_def: PrintableString {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_PRINTABLE_STRING);} + | PrintableString size_def {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_PRINTABLE_STRING|CONST_SIZE); _asn1_set_down($$,$2);} ; -universalstring_def: UniversalString {$$=_asn1_add_static_node(ASN1_ETYPE_UNIVERSAL_STRING);} - | UniversalString size_def {$$=_asn1_add_static_node(ASN1_ETYPE_UNIVERSAL_STRING|CONST_SIZE); +universalstring_def: UniversalString {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_UNIVERSAL_STRING);} + | UniversalString size_def {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_UNIVERSAL_STRING|CONST_SIZE); _asn1_set_down($$,$2);} ; -bmpstring_def: BMPString {$$=_asn1_add_static_node(ASN1_ETYPE_BMP_STRING);} - | BMPString size_def {$$=_asn1_add_static_node(ASN1_ETYPE_BMP_STRING|CONST_SIZE); +bmpstring_def: BMPString {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_BMP_STRING);} + | BMPString size_def {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_BMP_STRING|CONST_SIZE); _asn1_set_down($$,$2);} ; -utf8string_def: UTF8String {$$=_asn1_add_static_node(ASN1_ETYPE_UTF8_STRING);} - | UTF8String size_def {$$=_asn1_add_static_node(ASN1_ETYPE_UTF8_STRING|CONST_SIZE); +utf8string_def: UTF8String {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_UTF8_STRING);} + | UTF8String size_def {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_UTF8_STRING|CONST_SIZE); _asn1_set_down($$,$2);} ; -visiblestring_def: VisibleString {$$=_asn1_add_static_node(ASN1_ETYPE_VISIBLE_STRING);} - | VisibleString size_def {$$=_asn1_add_static_node(ASN1_ETYPE_VISIBLE_STRING|CONST_SIZE); +visiblestring_def: VisibleString {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_VISIBLE_STRING);} + | VisibleString size_def {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_VISIBLE_STRING|CONST_SIZE); _asn1_set_down($$,$2);} ; -octet_string_def : OCTET STRING {$$=_asn1_add_static_node(ASN1_ETYPE_OCTET_STRING);} - | OCTET STRING size_def {$$=_asn1_add_static_node(ASN1_ETYPE_OCTET_STRING|CONST_SIZE); +octet_string_def : OCTET STRING {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_OCTET_STRING);} + | OCTET STRING size_def {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_OCTET_STRING|CONST_SIZE); _asn1_set_down($$,$3);} ; -bit_element : IDENTIFIER'('NUM')' {$$=_asn1_add_static_node(ASN1_ETYPE_CONSTANT); +bit_element : IDENTIFIER'('NUM')' {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_CONSTANT); _asn1_set_name($$,$1); _asn1_set_value($$,$3,strlen($3)+1);} ; @@ -311,25 +321,25 @@ bit_element_list : bit_element {$$=$1;} _asn1_set_right(_asn1_get_last_right($1),$3);} ; -bit_string_def : BIT STRING {$$=_asn1_add_static_node(ASN1_ETYPE_BIT_STRING);} - | BIT STRING size_def {$$=_asn1_add_static_node(ASN1_ETYPE_BIT_STRING|CONST_SIZE);} +bit_string_def : BIT STRING {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_BIT_STRING);} + | BIT STRING size_def {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_BIT_STRING|CONST_SIZE);} | BIT STRING'{'bit_element_list'}' - {$$=_asn1_add_static_node(ASN1_ETYPE_BIT_STRING|CONST_LIST); + {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_BIT_STRING|CONST_LIST); _asn1_set_down($$,$4);} ; enumerated_def : ENUMERATED'{'bit_element_list'}' - {$$=_asn1_add_static_node(ASN1_ETYPE_ENUMERATED|CONST_LIST); + {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_ENUMERATED|CONST_LIST); _asn1_set_down($$,$3);} ; -object_def : OBJECT STR_IDENTIFIER {$$=_asn1_add_static_node(ASN1_ETYPE_OBJECT_ID);} +object_def : OBJECT STR_IDENTIFIER {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_OBJECT_ID);} ; -type_assig_right: IDENTIFIER {$$=_asn1_add_static_node(ASN1_ETYPE_IDENTIFIER); +type_assig_right: IDENTIFIER {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_IDENTIFIER); _asn1_set_value($$,$1,strlen($1)+1);} - | IDENTIFIER size_def {$$=_asn1_add_static_node(ASN1_ETYPE_IDENTIFIER|CONST_SIZE); + | IDENTIFIER size_def {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_IDENTIFIER|CONST_SIZE); _asn1_set_value($$,$1,strlen($1)+1); _asn1_set_down($$,$2);} | integer_def {$$=$1;} @@ -352,7 +362,7 @@ type_assig_right: IDENTIFIER {$$=_asn1_add_static_node(ASN1_ETYPE_IDENT | choise_def {$$=$1;} | any_def {$$=$1;} | set_def {$$=$1;} - | TOKEN_NULL {$$=_asn1_add_static_node(ASN1_ETYPE_NULL);} + | TOKEN_NULL {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_NULL);} ; type_assig_right_tag : type_assig_right {$$=$1;} @@ -376,31 +386,31 @@ type_assig_list : type_assig {$$=$1;} _asn1_set_right(_asn1_get_last_right($1),$3);} ; -sequence_def : SEQUENCE'{'type_assig_list'}' {$$=_asn1_add_static_node(ASN1_ETYPE_SEQUENCE); +sequence_def : SEQUENCE'{'type_assig_list'}' {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_SEQUENCE); _asn1_set_down($$,$3);} - | SEQUENCE OF type_assig_right {$$=_asn1_add_static_node(ASN1_ETYPE_SEQUENCE_OF); + | SEQUENCE OF type_assig_right {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_SEQUENCE_OF); _asn1_set_down($$,$3);} - | SEQUENCE size_def OF type_assig_right {$$=_asn1_add_static_node(ASN1_ETYPE_SEQUENCE_OF|CONST_SIZE); + | SEQUENCE size_def OF type_assig_right {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_SEQUENCE_OF|CONST_SIZE); _asn1_set_right($2,$4); _asn1_set_down($$,$2);} ; -set_def : SET'{'type_assig_list'}' {$$=_asn1_add_static_node(ASN1_ETYPE_SET); +set_def : SET'{'type_assig_list'}' {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_SET); _asn1_set_down($$,$3);} - | SET OF type_assig_right {$$=_asn1_add_static_node(ASN1_ETYPE_SET_OF); + | SET OF type_assig_right {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_SET_OF); _asn1_set_down($$,$3);} - | SET size_def OF type_assig_right {$$=_asn1_add_static_node(ASN1_ETYPE_SET_OF|CONST_SIZE); + | SET size_def OF type_assig_right {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_SET_OF|CONST_SIZE); _asn1_set_right($2,$4); _asn1_set_down($$,$2);} ; -choise_def : CHOICE'{'type_assig_list'}' {$$=_asn1_add_static_node(ASN1_ETYPE_CHOICE); +choise_def : CHOICE'{'type_assig_list'}' {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_CHOICE); _asn1_set_down($$,$3);} ; -any_def : ANY {$$=_asn1_add_static_node(ASN1_ETYPE_ANY);} - | ANY DEFINED BY IDENTIFIER {$$=_asn1_add_static_node(ASN1_ETYPE_ANY|CONST_DEFINED_BY); - _asn1_set_down($$,_asn1_add_static_node(ASN1_ETYPE_CONSTANT)); +any_def : ANY {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_ANY);} + | ANY DEFINED BY IDENTIFIER {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_ANY|CONST_DEFINED_BY); + _asn1_set_down($$,_asn1_add_static_node(&e_list, ASN1_ETYPE_CONSTANT)); _asn1_set_name(_asn1_get_down($$),$4);} ; @@ -410,16 +420,16 @@ type_def : IDENTIFIER "::=" type_assig_right_tag {$$=_asn1_set_name($3,$1);} ; constant_def : IDENTIFIER OBJECT STR_IDENTIFIER "::=" '{'obj_constant_list'}' - {$$=_asn1_add_static_node(ASN1_ETYPE_OBJECT_ID|CONST_ASSIGN); + {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_OBJECT_ID|CONST_ASSIGN); _asn1_set_name($$,$1); _asn1_set_down($$,$6);} | IDENTIFIER IDENTIFIER "::=" '{' obj_constant_list '}' - {$$=_asn1_add_static_node(ASN1_ETYPE_OBJECT_ID|CONST_ASSIGN|CONST_1_PARAM); + {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_OBJECT_ID|CONST_ASSIGN|CONST_1_PARAM); _asn1_set_name($$,$1); _asn1_set_value($$,$2,strlen($2)+1); _asn1_set_down($$,$5);} | IDENTIFIER INTEGER "::=" pos_neg_num - {$$=_asn1_add_static_node(ASN1_ETYPE_INTEGER|CONST_ASSIGN); + {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_INTEGER|CONST_ASSIGN); _asn1_set_name($$,$1); _asn1_set_value($$,$4,strlen($4)+1);} ; @@ -433,29 +443,29 @@ type_constant_list : type_constant {$$=$1;} _asn1_set_right(_asn1_get_last_right($1),$2);} ; -definitions_id : IDENTIFIER '{' obj_constant_list '}' {$$=_asn1_add_static_node(ASN1_ETYPE_OBJECT_ID); +definitions_id : IDENTIFIER '{' obj_constant_list '}' {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_OBJECT_ID); _asn1_set_down($$,$3); _asn1_set_name($$,$1);} - | IDENTIFIER '{' '}' {$$=_asn1_add_static_node(ASN1_ETYPE_OBJECT_ID); + | IDENTIFIER '{' '}' {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_OBJECT_ID); _asn1_set_name($$,$1);} - | IDENTIFIER {$$=_asn1_add_static_node(ASN1_ETYPE_OBJECT_ID); + | IDENTIFIER {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_OBJECT_ID); _asn1_set_name($$,$1);} ; /* -identifier_list : IDENTIFIER {$$=_asn1_add_static_node(ASN1_ETYPE_IDENTIFIER); +identifier_list : IDENTIFIER {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_IDENTIFIER); _asn1_set_name($$,$1);} | identifier_list IDENTIFIER {$$=$1; - _asn1_set_right(_asn1_get_last_right($$),_asn1_add_static_node(ASN1_ETYPE_IDENTIFIER)); + _asn1_set_right(_asn1_get_last_right($$),_asn1_add_static_node(&e_list, ASN1_ETYPE_IDENTIFIER)); _asn1_set_name(_asn1_get_last_right($$),$2);} ; imports_def : empty {$$=NULL;} | IMPORTS identifier_list FROM IDENTIFIER obj_constant_list - {$$=_asn1_add_static_node(ASN1_ETYPE_IMPORTS); - _asn1_set_down($$,_asn1_add_static_node(ASN1_ETYPE_OBJECT_ID)); + {$$=_asn1_add_static_node(&e_list, ASN1_ETYPE_IMPORTS); + _asn1_set_down($$,_asn1_add_static_node(&e_list, ASN1_ETYPE_OBJECT_ID)); _asn1_set_name(_asn1_get_down($$),$4); _asn1_set_down(_asn1_get_down($$),$5); _asn1_set_right($$,$2);} @@ -697,23 +707,33 @@ asn1_parser2tree (const char *file, asn1_node * definitions, if (result_parse == ASN1_SUCCESS) { /* all identifier defined */ /* Delete the list and keep the ASN1 structure */ - _asn1_delete_list (); + _asn1_delete_list (e_list); + e_list = NULL; /* Convert into DER coding the value assign to INTEGER constants */ _asn1_change_integer_value (p_tree); /* Expand the IDs of OBJECT IDENTIFIER constants */ - _asn1_expand_object_id (p_tree); + result_parse = _asn1_expand_object_id (e_list, p_tree); + if (result_parse != ASN1_SUCCESS) + goto error; *definitions = p_tree; } else /* some identifiers not defined */ - /* Delete the list and the ASN1 structure */ - _asn1_delete_list_and_nodes (); + { + /* Delete the list and the ASN1 structure */ + _asn1_delete_list_and_nodes (e_list); + e_list = NULL; + } } else /* syntax error */ - /* Delete the list and the ASN1 structure */ - _asn1_delete_list_and_nodes (); + { + /* Delete the list and the ASN1 structure */ + _asn1_delete_list_and_nodes (e_list); + e_list = NULL; + } } + error: _asn1_create_errorDescription (result_parse, error_desc); return result_parse; @@ -804,7 +824,7 @@ asn1_parser2array (const char *inputFileName, const char *outputFileName, { /* file_out_name = inputFileName + _asn1_tab.c */ file_out_name = malloc (dot_p - inputFileName + 1 + - strlen ("_asn1_tab.c")); + sizeof ("_asn1_tab.c")-1); memcpy (file_out_name, inputFileName, dot_p - inputFileName); file_out_name[dot_p - inputFileName] = 0; @@ -820,12 +840,20 @@ asn1_parser2array (const char *inputFileName, const char *outputFileName, if (vectorName == NULL) { + unsigned len, i; /* vector_name = file name + _asn1_tab */ vector_name = malloc (dot_p - slash_p + 1 + - strlen ("_asn1_tab")); + sizeof("_asn1_tab") - 1); memcpy (vector_name, slash_p, dot_p - slash_p); vector_name[dot_p - slash_p] = 0; strcat (vector_name, "_asn1_tab"); + + len = strlen(vector_name); + for (i=0;i<len;i++) + { + if (vector_name[i] == '-') + vector_name[i] = '_'; + } } else { @@ -844,7 +872,8 @@ asn1_parser2array (const char *inputFileName, const char *outputFileName, } /* result == OK */ /* Delete the list and the ASN1 structure */ - _asn1_delete_list_and_nodes (); + _asn1_delete_list_and_nodes (e_list); + e_list = NULL; } /* inputFile exist */ _asn1_create_errorDescription (result_parse, error_desc); |