Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/openssl/openssl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2002-11-27 15:25:52 +0300
committerRichard Levitte <levitte@openssl.org>2002-11-27 15:25:52 +0300
commit0a3af9a4038045ba59bcf10a4f9e0b6bb5107cd8 (patch)
tree6727af9f1d470110f1fe40bcdaf1fc4fba1669ce /crypto/mem.c
parent3a08cf3bfb585b76443d412e93883cc8b50529ee (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;
}