diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2014-05-10 13:49:32 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2014-05-10 13:51:25 +0200 |
commit | 1a1a7a8a27b15e31a408b8cb787e4045eaa57f87 (patch) | |
tree | 4aecda17254a6c6aade6a2f90fd1ae700d391765 | |
parent | 0e6e66769c09e9653e7bbc41e40f4c6a6720305b (diff) | |
download | libtasn1-1a1a7a8a27b15e31a408b8cb787e4045eaa57f87.tar.gz libtasn1-1a1a7a8a27b15e31a408b8cb787e4045eaa57f87.tar.bz2 libtasn1-1a1a7a8a27b15e31a408b8cb787e4045eaa57f87.zip |
prevent memset() from being optimized out.
-rw-r--r-- | lib/gstr.h | 15 | ||||
-rw-r--r-- | lib/parser_aux.c | 5 |
2 files changed, 18 insertions, 2 deletions
@@ -25,3 +25,18 @@ void _asn1_str_cat (char *dest, size_t dest_tot_size, const char *src); #define Estrcpy(x,y) _asn1_str_cpy(x,ASN1_MAX_ERROR_DESCRIPTION_SIZE,y) #define Estrcat(x,y) _asn1_str_cat(x,ASN1_MAX_ERROR_DESCRIPTION_SIZE,y) + +inline static +void safe_memset(void *data, int c, size_t size) +{ + volatile unsigned volatile_zero = 0; + volatile char *vdata = (volatile char*)data; + + /* This is based on a nice trick for safe memset, + * sent by David Jacobson in the openssl-dev mailing list. + */ + + do { + memset(data, c, size); + } while(vdata[volatile_zero] != c); +} diff --git a/lib/parser_aux.c b/lib/parser_aux.c index b5f665d..6b34512 100644 --- a/lib/parser_aux.c +++ b/lib/parser_aux.c @@ -458,8 +458,9 @@ _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 (flags & ASN1_DELETE_FLAG_ZEROIZE && node->value) { + safe_memset(node->value, 0, node->value_len); + } if (node->value != NULL && node->value != node->small_value) free (node->value); |