summaryrefslogtreecommitdiffstats
path: root/crypto/init.c
diff options
context:
space:
mode:
authorRich Salz <rsalz@openssl.org>2016-07-08 13:40:08 -0400
committerRich Salz <rsalz@openssl.org>2017-01-12 11:27:27 -0500
commitf7edeced4d8d3f650c5ee32f20ba7165da4e3067 (patch)
tree53685ab2f88fb0c8c096abce029a4d18fe1d14ec /crypto/init.c
parent329f2f4a428b0acb7a579869a13f6cd6bf0a3551 (diff)
Add "random malloc failure" tooling
Still needs to be documented, somehow/somewhere. The env var OPENSSL_MALLOC_FAILURES controls how often malloc/realloc should fail. It's a set of fields separated by semicolons. Each field is a count and optional percentage (separated by @) which defaults to 100. If count is zero then it lasts "forever." For example: 100;@25 means the first 100 allocations pass, then the rest have a 25% chance of failing until the program exits or crashes. If env var OPENSSL_MALLOC_FD parses as a positive integer, a record of all malloc "shouldfail" tests is written to that file descriptor. If a malloc will fail, and OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE is not set (platform specific), then a backtrace will be written to the descriptor when a malloc fails. This can be useful because a malloc may fail but not be checked, and problems will only occur later. Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/1252)
Diffstat (limited to 'crypto/init.c')
-rw-r--r--crypto/init.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/crypto/init.c b/crypto/init.c
index 3f91119407..8036654c11 100644
--- a/crypto/init.c
+++ b/crypto/init.c
@@ -68,6 +68,9 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_base)
#ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_base: Setting up stop handlers\n");
#endif
+#ifndef OPENSSL_NO_CRYPTO_MDEBUG
+ ossl_malloc_setup_failures();
+#endif
/*
* We use a dummy thread local key here. We use the destructor to detect
* when the thread is going to stop (where that feature is available)