diff options
49 files changed, 1646 insertions, 887 deletions
@@ -152,6 +152,12 @@ [Richard Levitte] + *) Revamped memory debug; only -DCRYPTO_MDEBUG and -DCRYPTO_MDEBUG_ABORT + are used; the latter aborts on memory leaks (usually checked on exit). + Some undocumented "set malloc, etc., hooks" functions were removed + and others were changed. All are now documented. + [Rich Salz] + *) In DSA_generate_parameters_ex, if the provided seed is too short, return an error [Rich Salz and Ismo Puustinen <ismo.puustinen@intel.com>] diff --git a/Configurations/10-main.conf b/Configurations/10-main.conf index a82b95db64..4bd4366514 100644 --- a/Configurations/10-main.conf +++ b/Configurations/10-main.conf @@ -132,7 +132,7 @@ # -mcpu=ultrasparc inherit_from => [ "solaris-sparcv7-gcc", asm("sparcv9_asm") ], cflags => sub { join(" ","-m32 -mcpu=ultrasparc",@_); }, - debug_cflags => "-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG_ALL -DPEDANTIC -O -g -pedantic -ansi -Wshadow -Wno-long-long -D__EXTENSIONS__", + debug_cflags => "-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DPEDANTIC -O -g -pedantic -ansi -Wshadow -Wno-long-long -D__EXTENSIONS__", }, "solaris64-sparcv9-gcc" => { inherit_from => [ "solaris-sparcv9-gcc" ], @@ -150,7 +150,7 @@ inherit_from => [ "solaris-common" ], cc => "cc", cflags => sub { join(" ","-xstrconst -Xa -DB_ENDIAN -DBN_DIV2W",@_) }, - debug_cflags => "-g -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG_ALL", + debug_cflags => "-g -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG", release_cflags => "-xO5 -xdepend", thread_cflag => "-D_REENTRANT", lflags => sub { join(" ",@_,"-mt -lpthread") }, @@ -97,7 +97,7 @@ my $usage="Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [experimenta # Minimum warning options... any contributions to OpenSSL should at least get # past these. -my $gcc_devteam_warn = "-Wall -pedantic -DPEDANTIC -Wno-long-long -Wsign-compare -Wmissing-prototypes -Wshadow -Wformat -Wtype-limits -Werror -DCRYPTO_MDEBUG_ALL -DCRYPTO_MDEBUG_ABORT -DREF_CHECK -DDEBUG_UNUSED"; +my $gcc_devteam_warn = "-Wall -pedantic -DPEDANTIC -Wno-long-long -Wsign-compare -Wmissing-prototypes -Wshadow -Wformat -Wtype-limits -Werror -DCRYPTO_MDEBUG -DCRYPTO_MDEBUG_ABORT -DREF_CHECK -DDEBUG_UNUSED"; # These are used in addition to $gcc_devteam_warn when the compiler is clang. # TODO(openssl-team): fix problems and investigate if (at least) the diff --git a/apps/openssl.c b/apps/openssl.c index f2c7ccf0c4..d21988e77f 100644 --- a/apps/openssl.c +++ b/apps/openssl.c @@ -171,7 +171,6 @@ static int apps_startup() #ifdef SIGPIPE signal(SIGPIPE, SIG_IGN); #endif - CRYPTO_malloc_init(); ERR_load_crypto_strings(); ERR_load_SSL_strings(); @@ -311,15 +310,8 @@ int main(int argc, char *argv[]) #endif p = getenv("OPENSSL_DEBUG_MEMORY"); - if (p == NULL) - /* if not set, use compiled-in default */ - ; - else if (strcmp(p, "off") != 0) { - CRYPTO_malloc_debug_init(); - CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL); - } else { - CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0); - } + if (p != NULL && strcmp(p, "on") == 0) + CRYPTO_set_mem_debug(1); CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); CRYPTO_set_locking_callback(lock_dbg_cb); @@ -437,7 +429,9 @@ int main(int argc, char *argv[]) BIO_free(bio_in); BIO_free_all(bio_out); apps_shutdown(); +#ifdef CRYPTO_MDEBUG CRYPTO_mem_leaks(bio_err); +#endif BIO_free(bio_err); return (ret); } diff --git a/crypto/cms/Makefile b/crypto/cms/Makefile index 832c731114..e18e9ad07a 100644 --- a/crypto/cms/Makefile +++ b/crypto/cms/Makefile @@ -160,15 +160,16 @@ cms_env.o: ../include/internal/asn1_int.h ../include/internal/cryptlib.h cms_env.o: cms_env.c cms_lcl.h cms_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h cms_err.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h -cms_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h -cms_err.o: ../../include/openssl/ec.h ../../include/openssl/err.h -cms_err.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h -cms_err.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h -cms_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h -cms_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h -cms_err.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h -cms_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h -cms_err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +cms_err.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h +cms_err.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h +cms_err.o: ../../include/openssl/err.h ../../include/openssl/evp.h +cms_err.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h +cms_err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +cms_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h +cms_err.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h +cms_err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +cms_err.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h +cms_err.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h cms_err.o: cms_err.c cms_ess.o: ../../e_os.h ../../include/openssl/asn1.h cms_ess.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h @@ -188,17 +189,18 @@ cms_ess.o: ../../include/openssl/x509v3.h ../include/internal/cryptlib.h cms_ess.o: cms_ess.c cms_lcl.h cms_io.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h cms_io.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h -cms_io.o: ../../include/openssl/cms.h ../../include/openssl/crypto.h -cms_io.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h -cms_io.o: ../../include/openssl/err.h ../../include/openssl/evp.h -cms_io.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h -cms_io.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h -cms_io.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h -cms_io.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h -cms_io.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h -cms_io.o: ../../include/openssl/sha.h ../../include/openssl/stack.h -cms_io.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h -cms_io.o: ../../include/openssl/x509_vfy.h cms_io.c cms_lcl.h +cms_io.o: ../../include/openssl/cms.h ../../include/openssl/conf.h +cms_io.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h +cms_io.o: ../../include/openssl/ec.h ../../include/openssl/err.h +cms_io.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h +cms_io.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h +cms_io.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +cms_io.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h +cms_io.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h +cms_io.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +cms_io.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h +cms_io.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +cms_io.o: ../../include/openssl/x509v3.h cms_io.c cms_lcl.h cms_kari.o: ../../e_os.h ../../include/openssl/aes.h cms_kari.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h cms_kari.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h diff --git a/crypto/ct/Makefile b/crypto/ct/Makefile index 49771d9681..e4fb65b77c 100644 --- a/crypto/ct/Makefile +++ b/crypto/ct/Makefile @@ -70,7 +70,8 @@ ct_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h ct_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h ct_err.o: ../../include/openssl/symhacks.h ../include/internal/ct_int.h ct_err.o: ct_err.c -ct_lib.o: ../../e_os.h ../../include/openssl/asn1.h +ct_lib.o: ../../e_os.h ../../include/internal/dane.h +ct_lib.o: ../../include/internal/numbers.h ../../include/openssl/asn1.h ct_lib.o: ../../include/openssl/async.h ../../include/openssl/bio.h ct_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h ct_lib.o: ../../include/openssl/comp.h ../../include/openssl/crypto.h diff --git a/crypto/dh/Makefile b/crypto/dh/Makefile index 757ccf01fe..86e3c2c6b1 100644 --- a/crypto/dh/Makefile +++ b/crypto/dh/Makefile @@ -65,17 +65,19 @@ clean: dh_ameth.o: ../../e_os.h ../../include/openssl/asn1.h dh_ameth.o: ../../include/openssl/bio.h ../../include/openssl/bn.h dh_ameth.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h -dh_ameth.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h -dh_ameth.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h -dh_ameth.o: ../../include/openssl/err.h ../../include/openssl/evp.h -dh_ameth.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h -dh_ameth.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +dh_ameth.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h +dh_ameth.o: ../../include/openssl/dh.h ../../include/openssl/e_os2.h +dh_ameth.o: ../../include/openssl/ec.h ../../include/openssl/err.h +dh_ameth.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h +dh_ameth.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h +dh_ameth.o: ../../include/openssl/opensslconf.h dh_ameth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h dh_ameth.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h dh_ameth.o: ../../include/openssl/sha.h ../../include/openssl/stack.h dh_ameth.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h -dh_ameth.o: ../../include/openssl/x509_vfy.h ../include/internal/asn1_int.h -dh_ameth.o: ../include/internal/cryptlib.h dh_ameth.c +dh_ameth.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h +dh_ameth.o: ../include/internal/asn1_int.h ../include/internal/cryptlib.h +dh_ameth.o: dh_ameth.c dh_asn1.o: ../../e_os.h ../../include/openssl/asn1.h dh_asn1.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h dh_asn1.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h @@ -121,15 +123,16 @@ dh_gen.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h dh_gen.o: ../include/internal/cryptlib.h dh_gen.c dh_kdf.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h dh_kdf.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h -dh_kdf.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h -dh_kdf.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h -dh_kdf.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h -dh_kdf.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h -dh_kdf.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h -dh_kdf.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h -dh_kdf.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h -dh_kdf.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h -dh_kdf.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +dh_kdf.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h +dh_kdf.o: ../../include/openssl/dh.h ../../include/openssl/e_os2.h +dh_kdf.o: ../../include/openssl/ec.h ../../include/openssl/evp.h +dh_kdf.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h +dh_kdf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +dh_kdf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h +dh_kdf.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h +dh_kdf.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +dh_kdf.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h +dh_kdf.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h dh_kdf.o: dh_kdf.c dh_key.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h dh_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h diff --git a/crypto/dsa/Makefile b/crypto/dsa/Makefile index 5f4fb520e1..796d8a3fdc 100644 --- a/crypto/dsa/Makefile +++ b/crypto/dsa/Makefile @@ -65,18 +65,19 @@ clean: dsa_ameth.o: ../../e_os.h ../../include/openssl/asn1.h dsa_ameth.o: ../../include/openssl/bio.h ../../include/openssl/bn.h dsa_ameth.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h -dsa_ameth.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h -dsa_ameth.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h -dsa_ameth.o: ../../include/openssl/err.h ../../include/openssl/evp.h -dsa_ameth.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h -dsa_ameth.o: ../../include/openssl/objects.h +dsa_ameth.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h +dsa_ameth.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h +dsa_ameth.o: ../../include/openssl/ec.h ../../include/openssl/err.h +dsa_ameth.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h +dsa_ameth.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h dsa_ameth.o: ../../include/openssl/opensslconf.h dsa_ameth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h dsa_ameth.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h dsa_ameth.o: ../../include/openssl/sha.h ../../include/openssl/stack.h dsa_ameth.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h -dsa_ameth.o: ../../include/openssl/x509_vfy.h ../include/internal/asn1_int.h -dsa_ameth.o: ../include/internal/cryptlib.h dsa_ameth.c +dsa_ameth.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h +dsa_ameth.o: ../include/internal/asn1_int.h ../include/internal/cryptlib.h +dsa_ameth.o: dsa_ameth.c dsa_asn1.o: ../../e_os.h ../../include/openssl/asn1.h dsa_asn1.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h dsa_asn1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h diff --git a/crypto/ec/Makefile b/crypto/ec/Makefile index 7933898562..5abe958197 100644 --- a/crypto/ec/Makefile +++ b/crypto/ec/Makefile @@ -118,17 +118,19 @@ ec2_smpl.o: ec2_smpl.c ec_lcl.h ec_ameth.o: ../../e_os.h ../../include/openssl/asn1.h ec_ameth.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h ec_ameth.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h -ec_ameth.o: ../../include/openssl/cms.h ../../include/openssl/crypto.h -ec_ameth.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h -ec_ameth.o: ../../include/openssl/err.h ../../include/openssl/evp.h -ec_ameth.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h -ec_ameth.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +ec_ameth.o: ../../include/openssl/cms.h ../../include/openssl/conf.h +ec_ameth.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h +ec_ameth.o: ../../include/openssl/ec.h ../../include/openssl/err.h +ec_ameth.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h +ec_ameth.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h +ec_ameth.o: ../../include/openssl/opensslconf.h ec_ameth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h ec_ameth.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h ec_ameth.o: ../../include/openssl/sha.h ../../include/openssl/stack.h ec_ameth.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h -ec_ameth.o: ../../include/openssl/x509_vfy.h ../include/internal/asn1_int.h -ec_ameth.o: ../include/internal/cryptlib.h ec_ameth.c +ec_ameth.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h +ec_ameth.o: ../include/internal/asn1_int.h ../include/internal/cryptlib.h +ec_ameth.o: ec_ameth.c ec_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h ec_asn1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h ec_asn1.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h diff --git a/crypto/engine/eng_dyn.c b/crypto/engine/eng_dyn.c index 23f01cfc35..d19cab2ecf 100644 --- a/crypto/engine/eng_dyn.c +++ b/crypto/engine/eng_dyn.c @@ -506,8 +506,6 @@ static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx) * would also increase opaqueness. */ fns.static_state = ENGINE_get_static_state(); - CRYPTO_get_mem_functions(&fns.mem_fns.malloc_cb, - &fns.mem_fns.realloc_cb, &fns.mem_fns.free_cb); fns.lock_fns.lock_locking_cb = CRYPTO_get_locking_callback(); fns.lock_fns.lock_add_lock_cb = CRYPTO_get_add_lock_callback(); fns.lock_fns.dynlock_create_cb = CRYPTO_get_dynlock_create_callback(); diff --git a/crypto/mem.c b/crypto/mem.c index 939ad69775..ec9efea716 100644 --- a/crypto/mem.c +++ b/crypto/mem.c @@ -58,222 +58,63 @@ #include <stdio.h> #include <stdlib.h> +#include <limits.h> #include <openssl/crypto.h> #include "internal/cryptlib.h" -static int allow_customize = 1; /* we provide flexible functions for */ -static int allow_customize_debug = 1; /* exchanging memory-related functions - * at run-time, but this must be done - * before any blocks are actually - * allocated; or we'll run into huge - * problems when malloc/free pairs - * don't match etc. */ - /* * the following pointers may be changed as long as 'allow_customize' is set */ +static int allow_customize = 1; -static void *(*malloc_func) (size_t) = malloc; -static void *default_malloc_ex(size_t num, const char *file, int line) -{ - return malloc_func(num); -} - -static void *(*malloc_ex_func) (size_t, const char *file, int line) - = default_malloc_ex; - -static void *(*realloc_func) (void *, size_t) = realloc; -static void *default_realloc_ex(void *str, size_t num, - const char *file, int line) -{ - return realloc_func(str, num); -} - -static void *(*realloc_ex_func) (void *, size_t, const char *file, int line) - = default_realloc_ex; - -static void (*free_func) (void *) = free; - -static void *(*malloc_secure_func)(size_t) = malloc; -static void *default_malloc_secure_ex(size_t num, const char *file, int line) -{ - return malloc_secure_func(num); -} -static void *(*malloc_secure_ex_func)(size_t, const char *file, int line) - = default_malloc_secure_ex; -static void (*free_secure_func)(void *) = free; +static void *(*malloc_wrapper)(size_t, const char *, int) + = CRYPTO_malloc; +static void *(*realloc_wrapper)(void *, size_t, const char *, int) + = CRYPTO_realloc; +static void (*free_wrapper)(void *) + = CRYPTO_free; -/* may be changed as long as 'allow_customize_debug' is set */ -/* XXX use correct function pointer types */ #ifdef CRYPTO_MDEBUG -/* use default functions from mem_dbg.c */ -static void (*malloc_debug_func) (void *, size_t, const char *, int, int) - = CRYPTO_dbg_malloc; -static void (*realloc_debug_func) (void *, void *, size_t, const char *, int, - int) - = CRYPTO_dbg_realloc; -static void (*free_debug_func) (void *, int) = CRYPTO_dbg_free; -static void (*set_debug_options_func) (long) = CRYPTO_dbg_set_options; -static long (*get_debug_options_func) (void) = CRYPTO_dbg_get_options; +static int call_malloc_debug = 1; #else -/* - * applications can use CRYPTO_malloc_debug_init() to select above case at - * run-time - */ -static void (*malloc_debug_func) (void *, size_t, const char *, int, int) = NULL; -static void (*realloc_debug_func) (void *, void *, size_t, const char *, int, - int) - = NULL; -static void (*free_debug_func) (void *, int) = NULL; -static void (*set_debug_options_func) (long) = NULL; -static long (*get_debug_options_func) (void) = NULL; +static int call_malloc_debug = 0; #endif -int CRYPTO_set_mem_functions(void *(*m) (size_t), void *(*r) (void *, size_t), - void (*f) (void *)) -{ - /* Dummy call just to ensure OPENSSL_init() gets linked in */ - OPENSSL_init(); - if (!allow_customize) - return 0; - if ((m == 0) || (r == 0) || (f == 0)) - return 0; - malloc_func = m; - malloc_ex_func = default_malloc_ex; - realloc_func = r; - realloc_ex_func = default_realloc_ex; - free_func = f; - /* If user wants to intercept the secure or locked functions, do it - * after the basic functions. */ - malloc_secure_func = m; - malloc_secure_ex_func = default_malloc_secure_ex; - free_secure_func = f; - return 1; -} - -int CRYPTO_set_mem_ex_functions(void *(*m) (size_t, const char *, int), - void *(*r) (void *, size_t, const char *, - int), void (*f) (void *)) -{ - if (!allow_customize) - return 0; - if ((m == 0) || (r == 0) || (f == 0)) - return 0; - malloc_func = 0; - malloc_ex_func = m; - realloc_func = 0; - realloc_ex_func = r; - free_func = f; - malloc_secure_func = 0; - malloc_secure_ex_func = m; - free_secure_func = f; - return 1; -} - -int CRYPTO_set_secure_mem_functions(void *(*m)(size_t), void (*f)(void *)) +int CRYPTO_set_mem_functions( + void *(*m)(size_t, const char *, int), + void *(*r)(void *, size_t, const char *, int), + void (*f)(void *)) { - /* Dummy call just to ensure OPENSSL_init() gets linked in */ - OPENSSL_init(); if (!allow_customize) return 0; - if ((m == 0) || (f == 0)) - return 0; - malloc_secure_func = m; - malloc_secure_ex_func = default_malloc_secure_ex; - free_secure_func = f; + if (m) + malloc_wrapper = m; + if (r) + realloc_wrapper = r; + if (f) + free_wrapper = f; return 1; } -int CRYPTO_set_secure_mem_ex_functions(void *(*m)(size_t, const char *, int), - void (*f)(void *)) +int CRYPTO_set_mem_debug(int flag) { if (!allow_customize) return 0; - if ((m == NULL) || (f == NULL)) - return 0; - malloc_secure_func = 0; - malloc_secure_ex_func = m; - free_secure_func = f; - return 1; -} - -int CRYPTO_set_mem_debug_functions(void (*m) (void *, size_t, - const char *, int, int), - void (*r) (void *, void *, size_t, - const char *, int, int), - void (*f) (void *, int), void (*so) (long), - long (*go) (void)) -{ - if (!allow_customize_debug) - return 0; - malloc_debug_func = m; - realloc_debug_func = r; - free_debug_func = f; - set_debug_options_func = so; - get_debug_options_func = go; + call_malloc_debug = flag; return 1; } -void CRYPTO_get_mem_functions(void *(**m) (size_t), - void *(**r) (void *, size_t), - |