diff options
Diffstat (limited to 'lib/structure.c')
-rw-r--r-- | lib/structure.c | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/lib/structure.c b/lib/structure.c index 0545025..512dd60 100644 --- a/lib/structure.c +++ b/lib/structure.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2002-2014 Free Software Foundation, Inc. + * Copyright (C) 2002-2022 Free Software Foundation, Inc. * * This file is part of LIBTASN1. * @@ -78,8 +78,8 @@ _asn1_find_left (asn1_node_const node) int -_asn1_create_static_structure (asn1_node_const pointer, char *output_file_name, - char *vector_name) +_asn1_create_static_structure (asn1_node_const pointer, + char *output_file_name, char *vector_name) { FILE *file; asn1_node_const p; @@ -192,8 +192,7 @@ asn1_array2tree (const asn1_static_node * array, asn1_node * definitions, move = UP; - k = 0; - while (array[k].value || array[k].type || array[k].name) + for (k = 0; array[k].value || array[k].type || array[k].name; k++) { type = convert_old_type (array[k].type); @@ -207,9 +206,17 @@ asn1_array2tree (const asn1_static_node * array, asn1_node * definitions, *definitions = p; if (move == DOWN) - _asn1_set_down (p_last, p); + { + if (p_last && p_last->down) + _asn1_delete_structure (e_list, &p_last->down, 0); + _asn1_set_down (p_last, p); + } else if (move == RIGHT) - _asn1_set_right (p_last, p); + { + if (p_last && p_last->right) + _asn1_delete_structure (e_list, &p_last->right, 0); + _asn1_set_right (p_last, p); + } p_last = p; @@ -219,11 +226,8 @@ asn1_array2tree (const asn1_static_node * array, asn1_node * definitions, move = RIGHT; else { - while (1) + while (p_last != *definitions) { - if (p_last == *definitions) - break; - p_last = _asn1_find_up (p_last); if (p_last == NULL) @@ -237,7 +241,6 @@ asn1_array2tree (const asn1_static_node * array, asn1_node * definitions, } } /* while */ } - k++; } /* while */ if (p_last == *definitions) @@ -246,7 +249,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 (e_list, *definitions); + result = _asn1_expand_object_id (&e_list, *definitions); } } else @@ -290,13 +293,13 @@ asn1_array2tree (const asn1_static_node * array, asn1_node * definitions, int asn1_delete_structure (asn1_node * structure) { - return asn1_delete_structure2(structure, 0); + return _asn1_delete_structure (NULL, structure, 0); } /** * asn1_delete_structure2: * @structure: pointer to the structure that you want to delete. - * @flags: additional flags (see %ASN1_DELETE_FLAG) + * @flags: additional flags (see %ASN1_DELETE_FLAG_ZEROIZE) * * Deletes the structure *@structure. At the end, *@structure is set * to NULL. @@ -307,6 +310,13 @@ asn1_delete_structure (asn1_node * structure) int asn1_delete_structure2 (asn1_node * structure, unsigned int flags) { + return _asn1_delete_structure (NULL, structure, flags); +} + +int +_asn1_delete_structure (list_type * e_list, asn1_node * structure, + unsigned int flags) +{ asn1_node p, p2, p3; if (*structure == NULL) @@ -326,6 +336,8 @@ asn1_delete_structure2 (asn1_node * structure, unsigned int flags) { p3 = _asn1_find_up (p); _asn1_set_down (p3, p2); + if (e_list) + _asn1_delete_node_from_list (e_list, p); _asn1_remove_node (p, flags); p = p3; } @@ -345,6 +357,8 @@ asn1_delete_structure2 (asn1_node * structure, unsigned int flags) } else _asn1_set_right (p3, p2); + if (e_list) + _asn1_delete_node_from_list (e_list, p); _asn1_remove_node (p, flags); p = NULL; } @@ -356,7 +370,6 @@ asn1_delete_structure2 (asn1_node * structure, unsigned int flags) } - /** * asn1_delete_element: * @structure: pointer to the structure that contains the element you @@ -398,7 +411,6 @@ asn1_delete_element (asn1_node structure, const char *element_name) asn1_node _asn1_copy_structure3 (asn1_node_const source_node) { -/* FIXME: there may be a leak here */ asn1_node_const p_s; asn1_node dest_node, p_d, p_d_prev; int move; @@ -407,6 +419,8 @@ _asn1_copy_structure3 (asn1_node_const source_node) return NULL; dest_node = _asn1_add_single_node (source_node->type); + if (dest_node == NULL) + return dest_node; p_s = source_node; p_d = dest_node; @@ -879,7 +893,8 @@ asn1_print_structure (FILE * out, asn1_node_const structure, const char *name, fprintf (out, " value(%i):", (len - 1) * 8 - (p->value[len2])); for (k = 1; k < len; k++) - fprintf (out, "%02x", (unsigned) (p->value)[k + len2]); + fprintf (out, "%02x", + (unsigned) (p->value)[k + len2]); } } break; @@ -1101,7 +1116,8 @@ asn1_number_of_elements (asn1_node_const element, const char *name, int *num) * the OID. **/ const char * -asn1_find_structure_from_oid (asn1_node_const definitions, const char *oidValue) +asn1_find_structure_from_oid (asn1_node_const definitions, + const char *oidValue) { char name[2 * ASN1_MAX_NAME_SIZE + 2]; char value[ASN1_MAX_NAME_SIZE]; @@ -1122,7 +1138,7 @@ asn1_find_structure_from_oid (asn1_node_const definitions, const char *oidValue) if ((type_field (p->type) == ASN1_ETYPE_OBJECT_ID) && (p->type & CONST_ASSIGN)) { - snprintf(name, sizeof(name), "%s.%s", definitionsName, p->name); + snprintf (name, sizeof (name), "%s.%s", definitionsName, p->name); len = ASN1_MAX_NAME_SIZE; result = asn1_read_value (definitions, name, value, &len); @@ -1205,5 +1221,5 @@ asn1_copy_node (asn1_node dst, const char *dst_name, asn1_node asn1_dup_node (asn1_node_const src, const char *src_name) { - return _asn1_copy_structure2(src, src_name); + return _asn1_copy_structure2 (src, src_name); } |