Perturb the malloc output during tests
authorMatt Caswell <matt@openssl.org>
Thu, 24 Feb 2022 16:20:14 +0000 (16:20 +0000)
committerMatt Caswell <matt@openssl.org>
Thu, 3 Mar 2022 13:36:21 +0000 (13:36 +0000)
Set the environment variable MALLOC_PERTURB_ during tests to perturb the
output from OPENSSL_malloc() calls (see the mallopt man page for details
about this environment variable). This could be a low cost way of spotting
uninit reads in "make test" runs in some situations.

In tests I have found it to be a little unreliable (sometimes it seemed to
not perturb the output for inexplicable reasons) - but since this is easy
to implement I think it is worthwhile.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17768)

test/run_tests.pl

index 4899356a6ee8adacda92d3760cf666429c453ab8..4ee6a036a9769ccf09d1373b1b8eb6f123e2c0a0 100644 (file)
@@ -39,6 +39,11 @@ $ENV{OPENSSL_MODULES} = rel2abs(catdir($bldtop, "providers"));
 $ENV{OPENSSL_ENGINES} = rel2abs(catdir($bldtop, "engines"));
 $ENV{CTLOG_FILE} = rel2abs(catfile($srctop, "test", "ct", "log_list.cnf"));
 
+# On platforms that support this, this will ensure malloc returns data that is
+# set to a non-zero value. Can be helpful for detecting uninitialized reads in
+# some situations.
+$ENV{'MALLOC_PERTURB_'} = '128' if !defined $ENV{'MALLOC_PERTURB_'};
+
 my %tapargs =
     ( verbosity         => $ENV{HARNESS_VERBOSE} ? 1 : 0,
       lib               => [ $libdir ],