# define LOAD(x) tsan_load(&x)
# endif /* TSAN_REQUIRES_LOCKING */
-static char *md_failstring;
+static char md_failbuf[CRYPTO_MEM_CHECK_MAX_FS + 1];
+static char *md_failstring = NULL;
static long md_count;
static int md_fail_percent = 0;
static int md_tracefd = -1;
void ossl_malloc_setup_failures(void)
{
const char *cp = getenv("OPENSSL_MALLOC_FAILURES");
-
- if (cp != NULL && (md_failstring = strdup(cp)) != NULL)
- parseit();
+ size_t cplen = 0;
+
+ if (cp != NULL) {
+ /* if the value is too long we'll just ignore it */
+ cplen = strlen(cp);
+ if (cplen <= CRYPTO_MEM_CHECK_MAX_FS) {
+ strncpy(md_failbuf, cp, CRYPTO_MEM_CHECK_MAX_FS);
+ md_failstring = md_failbuf;
+ parseit();
+ }
+ }
if ((cp = getenv("OPENSSL_MALLOC_FD")) != NULL)
md_tracefd = atoi(cp);
if ((cp = getenv("OPENSSL_MALLOC_SEED")) != NULL)
to 100). If the count is zero, then it lasts forever. For example,
C<100;@25> or C<100@0;0@25> means the first 100 allocations pass, then all
other allocations (until the program exits or crashes) have a 25% chance of
-failing.
+failing. The length of the value of B<OPENSSL_MALLOC_FAILURES> must be 256 or
+fewer characters.
If the variable B<OPENSSL_MALLOC_FD> is parsed as a positive integer, then
it is taken as an open file descriptor. This is used in conjunction with
# define CRYPTO_MEM_CHECK_ENABLE 0x2 /* Control and mode bit */
# define CRYPTO_MEM_CHECK_DISABLE 0x3 /* Control only */
+/* max allowed length for value of OPENSSL_MALLOC_FAILURES env var. */
+# define CRYPTO_MEM_CHECK_MAX_FS 256
+
void CRYPTO_get_alloc_counts(int *mcount, int *rcount, int *fcount);
# ifndef OPENSSL_NO_DEPRECATED_3_0
# define OPENSSL_mem_debug_push(info) \