diff options
author | Richard Levitte <levitte@openssl.org> | 2002-11-27 13:24:05 +0100 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2002-11-27 13:24:05 +0100 |
commit | df29cc8f77bcf09cdd245feeaea452f5f91e4125 (patch) | |
tree | aa076e181f80d3f226b75ead2a447c5111d0b58d /crypto/mem.c | |
parent | I forgot that @ in strings must be escaped in Perl (diff) | |
download | openssl-df29cc8f77bcf09cdd245feeaea452f5f91e4125.tar.xz openssl-df29cc8f77bcf09cdd245feeaea452f5f91e4125.zip |
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.c | 14 |
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; } |