diff options
author | markus <> | 2003-05-12 02:18:40 +0000 |
---|---|---|
committer | markus <> | 2003-05-12 02:18:40 +0000 |
commit | d4fcd82bb7f6d603bd61e19a81ba97337b89dfca (patch) | |
tree | d52e3a0f1f08f65ad283027e560e17ed0d720462 /src/lib/libcrypto/mem.c | |
parent | 582bbd139cd2afd58d10dc051c5b0b989b441074 (diff) | |
download | openbsd-d4fcd82bb7f6d603bd61e19a81ba97337b89dfca.tar.gz openbsd-d4fcd82bb7f6d603bd61e19a81ba97337b89dfca.tar.bz2 openbsd-d4fcd82bb7f6d603bd61e19a81ba97337b89dfca.zip |
merge 0.9.7b with local changes; crank majors for libssl/libcrypto
Diffstat (limited to 'src/lib/libcrypto/mem.c')
-rw-r--r-- | src/lib/libcrypto/mem.c | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/src/lib/libcrypto/mem.c b/src/lib/libcrypto/mem.c index 87d0ebc714..29df7d35b2 100644 --- a/src/lib/libcrypto/mem.c +++ b/src/lib/libcrypto/mem.c | |||
@@ -250,6 +250,7 @@ void CRYPTO_get_mem_debug_functions(void (**m)(void *,int,const char *,int,int), | |||
250 | void *CRYPTO_malloc_locked(int num, const char *file, int line) | 250 | void *CRYPTO_malloc_locked(int num, const char *file, int line) |
251 | { | 251 | { |
252 | void *ret = NULL; | 252 | void *ret = NULL; |
253 | extern unsigned char cleanse_ctr; | ||
253 | 254 | ||
254 | if (num < 0) return NULL; | 255 | if (num < 0) return NULL; |
255 | 256 | ||
@@ -266,6 +267,12 @@ void *CRYPTO_malloc_locked(int num, const char *file, int line) | |||
266 | if (malloc_debug_func != NULL) | 267 | if (malloc_debug_func != NULL) |
267 | malloc_debug_func(ret, num, file, line, 1); | 268 | malloc_debug_func(ret, num, file, line, 1); |
268 | 269 | ||
270 | /* Create a dependency on the value of 'cleanse_ctr' so our memory | ||
271 | * sanitisation function can't be optimised out. NB: We only do | ||
272 | * this for >2Kb so the overhead doesn't bother us. */ | ||
273 | if(ret && (num > 2048)) | ||
274 | ((unsigned char *)ret)[0] = cleanse_ctr; | ||
275 | |||
269 | return ret; | 276 | return ret; |
270 | } | 277 | } |
271 | 278 | ||
@@ -284,6 +291,7 @@ void CRYPTO_free_locked(void *str) | |||
284 | void *CRYPTO_malloc(int num, const char *file, int line) | 291 | void *CRYPTO_malloc(int num, const char *file, int line) |
285 | { | 292 | { |
286 | void *ret = NULL; | 293 | void *ret = NULL; |
294 | extern unsigned char cleanse_ctr; | ||
287 | 295 | ||
288 | if (num < 0) return NULL; | 296 | if (num < 0) return NULL; |
289 | 297 | ||
@@ -300,6 +308,12 @@ void *CRYPTO_malloc(int num, const char *file, int line) | |||
300 | if (malloc_debug_func != NULL) | 308 | if (malloc_debug_func != NULL) |
301 | malloc_debug_func(ret, num, file, line, 1); | 309 | malloc_debug_func(ret, num, file, line, 1); |
302 | 310 | ||
311 | /* Create a dependency on the value of 'cleanse_ctr' so our memory | ||
312 | * sanitisation function can't be optimised out. NB: We only do | ||
313 | * this for >2Kb so the overhead doesn't bother us. */ | ||
314 | if(ret && (num > 2048)) | ||
315 | ((unsigned char *)ret)[0] = cleanse_ctr; | ||
316 | |||
303 | return ret; | 317 | return ret; |
304 | } | 318 | } |
305 | 319 | ||
@@ -310,8 +324,8 @@ void *CRYPTO_realloc(void *str, int num, const char *file, int line) | |||
310 | if (str == NULL) | 324 | if (str == NULL) |
311 | return CRYPTO_malloc(num, file, line); | 325 | return CRYPTO_malloc(num, file, line); |
312 | 326 | ||
313 | if (num < 0) return NULL; | 327 | if (num < 0) return NULL; |
314 | 328 | ||
315 | if (realloc_debug_func != NULL) | 329 | if (realloc_debug_func != NULL) |
316 | realloc_debug_func(str, NULL, num, file, line, 0); | 330 | realloc_debug_func(str, NULL, num, file, line, 0); |
317 | ret = realloc_ex_func(str,num,file,line); | 331 | ret = realloc_ex_func(str,num,file,line); |
@@ -324,6 +338,32 @@ void *CRYPTO_realloc(void *str, int num, const char *file, int line) | |||
324 | return ret; | 338 | return ret; |
325 | } | 339 | } |
326 | 340 | ||
341 | void *CRYPTO_realloc_clean(void *str, int old_len, int num, const char *file, | ||
342 | int line) | ||
343 | { | ||
344 | void *ret = NULL; | ||
345 | |||
346 | if (str == NULL) | ||
347 | return CRYPTO_malloc(num, file, line); | ||
348 | |||
349 | if (num < 0) return NULL; | ||
350 | |||
351 | if (realloc_debug_func != NULL) | ||
352 | realloc_debug_func(str, NULL, num, file, line, 0); | ||
353 | ret=malloc_ex_func(num,file,line); | ||
354 | if(ret) | ||
355 | memcpy(ret,str,old_len); | ||
356 | OPENSSL_cleanse(str,old_len); | ||
357 | free_func(str); | ||
358 | #ifdef LEVITTE_DEBUG_MEM | ||
359 | fprintf(stderr, "LEVITTE_DEBUG_MEM: | 0x%p -> 0x%p (%d)\n", str, ret, num); | ||
360 | #endif | ||
361 | if (realloc_debug_func != NULL) | ||
362 | realloc_debug_func(str, ret, num, file, line, 1); | ||
363 | |||
364 | return ret; | ||
365 | } | ||
366 | |||
327 | void CRYPTO_free(void *str) | 367 | void CRYPTO_free(void *str) |
328 | { | 368 | { |
329 | if (free_debug_func != NULL) | 369 | if (free_debug_func != NULL) |
@@ -343,7 +383,6 @@ void *CRYPTO_remalloc(void *a, int num, const char *file, int line) | |||
343 | return(a); | 383 | return(a); |
344 | } | 384 | } |
345 | 385 | ||
346 | |||
347 | void CRYPTO_set_mem_debug_options(long bits) | 386 | void CRYPTO_set_mem_debug_options(long bits) |
348 | { | 387 | { |
349 | if (set_debug_options_func != NULL) | 388 | if (set_debug_options_func != NULL) |