summaryrefslogtreecommitdiffstats
path: root/crypto/mem.c
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2002-11-27 12:24:05 +0000
committerRichard Levitte <levitte@openssl.org>2002-11-27 12:24:05 +0000
commitdf29cc8f77bcf09cdd245feeaea452f5f91e4125 (patch)
treeaa076e181f80d3f226b75ead2a447c5111d0b58d /crypto/mem.c
parentec7164133d09b1a8368ad064f501ab163f5cfebb (diff)
Add OPENSSL_cleanse() to help cleanse memory and avoid certain compiler
and linker optimizations. PR: 343
Diffstat (limited to 'crypto/mem.c')
-rw-r--r--crypto/mem.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/crypto/mem.c b/crypto/mem.c
index 03d2569bce..46a00697ce 100644
--- a/crypto/mem.c
+++ b/crypto/mem.c
@@ -250,6 +250,7 @@ void CRYPTO_get_mem_debug_functions(void (**m)(void *,int,const char *,int,int),
void *CRYPTO_malloc_locked(int num, const char *file, int line)
{
void *ret = NULL;
+ extern unsigned char cleanse_ctr;
allow_customize = 0;
if (malloc_debug_func != NULL)
@@ -264,6 +265,12 @@ void *CRYPTO_malloc_locked(int num, const char *file, int line)
if (malloc_debug_func != NULL)
malloc_debug_func(ret, num, file, line, 1);
+ /* Create a dependency on the value of 'cleanse_ctr' so our memory
+ * sanitisation function can't be optimised out. NB: We only do
+ * this for >2Kb so the overhead doesn't bother us. */
+ if(ret && (num > 2048))
+ ((unsigned char *)ret)[0] = cleanse_ctr;
+
return ret;
}
@@ -282,6 +289,7 @@ void CRYPTO_free_locked(void *str)
void *CRYPTO_malloc(int num, const char *file, int line)
{
void *ret = NULL;
+ extern unsigned char cleanse_ctr;
allow_customize = 0;
if (malloc_debug_func != NULL)
@@ -296,6 +304,12 @@ void *CRYPTO_malloc(int num, const char *file, int line)
if (malloc_debug_func != NULL)
malloc_debug_func(ret, num, file, line, 1);
+ /* Create a dependency on the value of 'cleanse_ctr' so our memory
+ * sanitisation function can't be optimised out. NB: We only do
+ * this for >2Kb so the overhead doesn't bother us. */
+ if(ret && (num > 2048))
+ ((unsigned char *)ret)[0] = cleanse_ctr;
+
return ret;
}