summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2013-11-13 13:55:14 +0100
committerNikos Mavrogiannopoulos <nmav@redhat.com>2013-11-13 13:55:16 +0100
commitc5a9cfaf1bc008a2b4b7bbd544a8f3ab3d62d953 (patch)
tree5d67b0c9adeb443dad2518b88699842b2b0f4968
parentef90ba764f1032f097ae77443651656b3d712ebf (diff)
downloadlibtasn1-c5a9cfaf1bc008a2b4b7bbd544a8f3ab3d62d953.tar.gz
libtasn1-c5a9cfaf1bc008a2b4b7bbd544a8f3ab3d62d953.tar.bz2
libtasn1-c5a9cfaf1bc008a2b4b7bbd544a8f3ab3d62d953.zip
Added asn1_delete_structure2().
The new function accepts additional flags to be used during deinitialization. For the moment the only available flag is ASN1_DELETE_FLAG_ZEROIZE which zeroizes all values in the structure prior to deinitialization.
-rw-r--r--NEWS2
-rw-r--r--lib/libtasn1.h8
-rw-r--r--lib/parser_aux.c10
-rw-r--r--lib/parser_aux.h2
-rw-r--r--lib/structure.c23
5 files changed, 38 insertions, 7 deletions
diff --git a/NEWS b/NEWS
index f7fc31a..99b7105 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
GNU Libtasn1 NEWS -*- outline -*-
* Noteworthy changes in release 3.4 (unreleased) [stable]
+- Added asn1_delete_structure2() which allows zeroizing the contents
+ of all values in the structure prior to deinitialization.
* Noteworthy changes in release 3.3 (released 2013-03-23) [stable]
- More precise overflow checks using gnulib's intprops module.
diff --git a/lib/libtasn1.h b/lib/libtasn1.h
index a2da884..f29e6a4 100644
--- a/lib/libtasn1.h
+++ b/lib/libtasn1.h
@@ -168,6 +168,12 @@ extern "C"
#define ASN1_ETYPE_UTC_TIME 36
#define ASN1_ETYPE_GENERALIZED_TIME 37
+/* Flags used by asn1_delete_structure2() */
+
+/* makes sure the values are zeroized prior to deinitialization */
+#define ASN1_DELETE_FLAG_ZEROIZE 1
+
+
struct asn1_data_node_st
{
const char *name; /* Node name */
@@ -214,6 +220,8 @@ extern "C"
extern ASN1_API int asn1_delete_structure (asn1_node * structure);
+ extern ASN1_API int asn1_delete_structure2 (asn1_node * structure, unsigned int flags);
+
extern ASN1_API int
asn1_delete_element (asn1_node structure, const char *element_name);
diff --git a/lib/parser_aux.c b/lib/parser_aux.c
index 34bf1e7..fccfed5 100644
--- a/lib/parser_aux.c
+++ b/lib/parser_aux.c
@@ -450,12 +450,16 @@ _asn1_get_last_right (asn1_node node)
/* element (not the elements pointed by it). */
/* Parameters: */
/* node: NODE_ASN element pointer. */
+/* flags: ASN1_DELETE_FLAG_* */
/******************************************************************/
void
-_asn1_remove_node (asn1_node node)
+_asn1_remove_node (asn1_node node, unsigned int flags)
{
if (node == NULL)
return;
+
+ if (flags & ASN1_DELETE_FLAG_ZEROIZE)
+ memset(node->value, 0, node->value_len);
if (node->value != NULL && node->value != node->small_value)
free (node->value);
@@ -517,7 +521,7 @@ _asn1_delete_list_and_nodes (void)
{
listElement = firstElement;
firstElement = firstElement->next;
- _asn1_remove_node (listElement->node);
+ _asn1_remove_node (listElement->node, 0);
free (listElement);
}
}
@@ -672,7 +676,7 @@ _asn1_expand_object_id (asn1_node node)
|| !(p3->type & CONST_ASSIGN))
return ASN1_ELEMENT_NOT_FOUND;
_asn1_set_down (p, p2->right);
- _asn1_remove_node (p2);
+ _asn1_remove_node (p2, 0);
p2 = p;
p4 = p3->down;
while (p4)
diff --git a/lib/parser_aux.h b/lib/parser_aux.h
index 24663eb..5fd4e64 100644
--- a/lib/parser_aux.h
+++ b/lib/parser_aux.h
@@ -48,7 +48,7 @@ asn1_node _asn1_set_right (asn1_node node, asn1_node right);
asn1_node _asn1_get_last_right (asn1_node node);
-void _asn1_remove_node (asn1_node node);
+void _asn1_remove_node (asn1_node node, unsigned int flags);
void _asn1_delete_list (void);
diff --git a/lib/structure.c b/lib/structure.c
index 22f1037..611ed94 100644
--- a/lib/structure.c
+++ b/lib/structure.c
@@ -287,6 +287,23 @@ asn1_array2tree (const asn1_static_node * array, asn1_node * definitions,
int
asn1_delete_structure (asn1_node * structure)
{
+ return asn1_delete_structure2(structure, 0);
+}
+
+/**
+ * asn1_delete_structure2:
+ * @structure: pointer to the structure that you want to delete.
+ * @flags: additional flags (see %ASN1_DELETE_FLAG)
+ *
+ * Deletes the structure *@structure. At the end, *@structure is set
+ * to NULL.
+ *
+ * Returns: %ASN1_SUCCESS if successful, %ASN1_ELEMENT_NOT_FOUND if
+ * *@structure was NULL.
+ **/
+int
+asn1_delete_structure2 (asn1_node * structure, unsigned int flags)
+{
asn1_node p, p2, p3;
if (*structure == NULL)
@@ -306,7 +323,7 @@ asn1_delete_structure (asn1_node * structure)
{
p3 = _asn1_find_up (p);
_asn1_set_down (p3, p2);
- _asn1_remove_node (p);
+ _asn1_remove_node (p, flags);
p = p3;
}
else
@@ -325,7 +342,7 @@ asn1_delete_structure (asn1_node * structure)
}
else
_asn1_set_right (p3, p2);
- _asn1_remove_node (p);
+ _asn1_remove_node (p, flags);
p = NULL;
}
}
@@ -598,7 +615,7 @@ _asn1_expand_identifier (asn1_node * node, asn1_node root)
if (p == *node)
*node = p2;
- _asn1_remove_node (p);
+ _asn1_remove_node (p, 0);
p = p2;
move = DOWN;
continue;