From 2f22074460817594a3fed3db46bb00b4ce11d00e Mon Sep 17 00:00:00 2001
From: Nikos Mavrogiannopoulos <nmav@redhat.com>
Date: Tue, 16 Jul 2019 14:27:56 +0200
Subject: [PATCH] _asn1_add_static_node: made thread safe

Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
---
 lib/ASN1.y       | 161 +++++++++++++++++++++++++++++--------------------------
 lib/parser_aux.c |  66 ++++++++++-------------
 lib/parser_aux.h |  24 ++++++---
 lib/structure.c  |   9 ++--
 4 files changed, 135 insertions(+), 125 deletions(-)

diff --git a/lib/ASN1.y b/lib/ASN1.y
index 1482fcd..cd783fe 100644
--- a/lib/ASN1.y
+++ b/lib/ASN1.y
@@ -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 */
@@ -144,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);
@@ -178,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);}
 ;
@@ -190,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);}
 ;
@@ -207,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);}
 ;
 
@@ -218,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);}
 ;
 
 
@@ -230,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);}
 ;
@@ -260,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);}
 ;
@@ -320,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;}
@@ -361,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;}
@@ -385,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);}
 ;
 
@@ -419,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);}
 ;
@@ -442,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);}
@@ -706,23 +707,30 @@ 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 */
-              result_parse = _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:
@@ -864,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);
diff --git a/lib/parser_aux.c b/lib/parser_aux.c
index 7d96bea..b182948 100644
--- a/lib/parser_aux.c
+++ b/lib/parser_aux.c
@@ -28,50 +28,37 @@
 
 char _asn1_identifierMissing[ASN1_MAX_NAME_SIZE + 1];	/* identifier name not found */
 
-/***********************************************/
-/* Type: list_type                             */
-/* Description: type used in the list during   */
-/* the structure creation.                     */
-/***********************************************/
-typedef struct list_struct
-{
-  asn1_node node;
-  struct list_struct *next;
-} list_type;
-
-
-/* Pointer to the first element of the list */
-list_type *firstElement = NULL;
 
 /******************************************************/
 /* Function : _asn1_add_static_node                   */
 /* Description: creates a new NODE_ASN element and    */
-/* puts it in the list pointed by firstElement.       */
+/* puts it in the list pointed by e_list.       */
 /* Parameters:                                        */
+/*   e_list: of type list_type; must be NULL initially */
 /*   type: type of the new element (see ASN1_ETYPE_   */
 /*         and CONST_ constants).                     */
 /* Return: pointer to the new element.                */
 /******************************************************/
 asn1_node
-_asn1_add_static_node (unsigned int type)
+_asn1_add_static_node (list_type **e_list, unsigned int type)
 {
-  list_type *listElement;
+  list_type *p;
   asn1_node punt;
 
   punt = calloc (1, sizeof (struct asn1_node_st));
   if (punt == NULL)
     return NULL;
 
-  listElement = malloc (sizeof (list_type));
-  if (listElement == NULL)
+  p = malloc (sizeof (list_type));
+  if (p == NULL)
     {
       free (punt);
       return NULL;
     }
 
-  listElement->node = punt;
-  listElement->next = firstElement;
-  firstElement = listElement;
+  p->node = punt;
+  p->next = *e_list;
+  *e_list = p;
 
   punt->type = type;
 
@@ -521,9 +508,9 @@ _asn1_find_up (asn1_node_const node)
 /* Description: deletes the list element given                    */
 /******************************************************************/
 static void
-_asn1_delete_node_from_list (asn1_node node)
+_asn1_delete_node_from_list (list_type *list, asn1_node node)
 {
-  list_type *p = firstElement;
+  list_type *p = list;
 
   while (p)
     {
@@ -539,15 +526,15 @@ _asn1_delete_node_from_list (asn1_node node)
 /*  pointed by them).                                             */
 /******************************************************************/
 void
-_asn1_delete_list (void)
+_asn1_delete_list (list_type *e_list)
 {
-  list_type *listElement;
+  list_type *p;
 
-  while (firstElement)
+  while (e_list)
     {
-      listElement = firstElement;
-      firstElement = firstElement->next;
-      free (listElement);
+      p = e_list;
+      e_list = e_list->next;
+      free (p);
     }
 }
 
@@ -557,16 +544,16 @@ _asn1_delete_list (void)
 /*  pointed by them.                                              */
 /******************************************************************/
 void
-_asn1_delete_list_and_nodes (void)
+_asn1_delete_list_and_nodes (list_type *e_list)
 {
-  list_type *listElement;
+  list_type *p;
 
-  while (firstElement)
+  while (e_list)
     {
-      listElement = firstElement;
-      firstElement = firstElement->next;
-      _asn1_remove_node (listElement->node, 0);
-      free (listElement);
+      p = e_list;
+      e_list = e_list->next;
+      _asn1_remove_node (p->node, 0);
+      free (p);
     }
 }
 
@@ -682,13 +669,14 @@ _asn1_change_integer_value (asn1_node node)
 /* Function : _asn1_expand_object_id                              */
 /* Description: expand the IDs of an OBJECT IDENTIFIER constant.  */
 /* Parameters:                                                    */
+/*   list: root of an object list                                 */
 /*   node: root of an ASN1 element.                               */
 /* Return:                                                        */
 /*   ASN1_ELEMENT_NOT_FOUND if NODE is NULL,                      */
 /*   otherwise ASN1_SUCCESS                                       */
 /******************************************************************/
 int
-_asn1_expand_object_id (asn1_node node)
+_asn1_expand_object_id (list_type *list, asn1_node node)
 {
   asn1_node p, p2, p3, p4, p5;
   char name_root[ASN1_MAX_NAME_SIZE], name2[2 * ASN1_MAX_NAME_SIZE + 1];
@@ -725,7 +713,7 @@ _asn1_expand_object_id (asn1_node node)
 			  || !(p3->type & CONST_ASSIGN))
 			return ASN1_ELEMENT_NOT_FOUND;
 		      _asn1_set_down (p, p2->right);
-		      _asn1_delete_node_from_list(p2);
+		      _asn1_delete_node_from_list(list, p2);
 		      _asn1_remove_node (p2, 0);
 		      p2 = p;
 		      p4 = p3->down;
diff --git a/lib/parser_aux.h b/lib/parser_aux.h
index 42e9071..c21d20d 100644
--- a/lib/parser_aux.h
+++ b/lib/parser_aux.h
@@ -22,10 +22,26 @@
 #ifndef _PARSER_AUX_H
 #define _PARSER_AUX_H
 
+/***********************************************/
+/* Type: list_type                             */
+/* Description: type used in the list during   */
+/* the structure creation.                     */
+/***********************************************/
+typedef struct list_struct
+{
+  asn1_node node;
+  struct list_struct *next;
+} list_type;
+
 /***************************************/
 /*  Functions used by ASN.1 parser     */
 /***************************************/
-asn1_node _asn1_add_static_node (unsigned int type);
+asn1_node _asn1_add_static_node (list_type **e_list, unsigned int type);
+
+void _asn1_delete_list (list_type *e_list);
+
+void _asn1_delete_list_and_nodes (list_type *e_list);
+
 
 asn1_node
 _asn1_set_value (asn1_node node, const void *value, unsigned int len);
@@ -48,10 +64,6 @@ asn1_node _asn1_get_last_right (asn1_node_const node);
 
 void _asn1_remove_node (asn1_node node, unsigned int flags);
 
-void _asn1_delete_list (void);
-
-void _asn1_delete_list_and_nodes (void);
-
 /* Max 64-bit integer length is 20 chars + 1 for sign + 1 for null termination */
 #define LTOSTR_MAX_SIZE 22
 char *_asn1_ltostr (int64_t v, char str[LTOSTR_MAX_SIZE]);
@@ -61,7 +73,7 @@ asn1_node _asn1_find_up (asn1_node_const node);
 int _asn1_change_integer_value (asn1_node node);
 
 #define EXPAND_OBJECT_ID_MAX_RECURSION 16
-int _asn1_expand_object_id (asn1_node node);
+int _asn1_expand_object_id (list_type *list, asn1_node node);
 
 int _asn1_type_set_config (asn1_node node);
 
diff --git a/lib/structure.c b/lib/structure.c
index 4b0ea2f..98393cc 100644
--- a/lib/structure.c
+++ b/lib/structure.c
@@ -182,6 +182,7 @@ asn1_array2tree (const asn1_static_node * array, asn1_node * definitions,
   int move;
   int result;
   unsigned int type;
+  list_type *e_list = NULL;
 
   if (errorDescription)
     errorDescription[0] = 0;
@@ -196,7 +197,7 @@ asn1_array2tree (const asn1_static_node * array, asn1_node * definitions,
     {
       type = convert_old_type (array[k].type);
 
-      p = _asn1_add_static_node (type & (~CONST_DOWN));
+      p = _asn1_add_static_node (&e_list, type & (~CONST_DOWN));
       if (array[k].name)
 	_asn1_set_name (p, array[k].name);
       if (array[k].value)
@@ -245,7 +246,7 @@ asn1_array2tree (const asn1_static_node * array, asn1_node * definitions,
       if (result == ASN1_SUCCESS)
 	{
 	  _asn1_change_integer_value (*definitions);
-	  result = _asn1_expand_object_id (*definitions);
+	  result = _asn1_expand_object_id (e_list, *definitions);
 	}
     }
   else
@@ -267,11 +268,11 @@ asn1_array2tree (const asn1_static_node * array, asn1_node * definitions,
 
   if (result != ASN1_SUCCESS)
     {
-      _asn1_delete_list_and_nodes ();
+      _asn1_delete_list_and_nodes (e_list);
       *definitions = NULL;
     }
   else
-    _asn1_delete_list ();
+    _asn1_delete_list (e_list);
 
   return result;
 }
-- 
1.8.3.1

