From: Junio C Hamano <gitster@pobox.com>
To: Elia Pinto <gitter.spiros@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] Add MALLOC_CHECK_ and MALLOC_PERTURB_ libc env to the test suite for detecting heap corruption
Date: Wed, 12 Sep 2012 10:51:46 -0700 [thread overview]
Message-ID: <7vy5kfceod.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <1347452248-12222-1-git-send-email-gitter.spiros@gmail.com> (Elia Pinto's message of "Wed, 12 Sep 2012 05:17:28 -0700")
Elia Pinto <gitter.spiros@gmail.com> writes:
> Recent versions of Linux libc (later than 5.4.23) and glibc (2.x)
> include a malloc() implementation which is tunable via environment
> variables. When MALLOC_CHECK_ is set, a special (less efficient)
> implementation is used which is designed to be tolerant against
> simple errors, such as double calls of free() with the same argument,
> or overruns of a single byte (off-by-one bugs). When MALLOC_CHECK_
> is set to 3, a diagnostic message is printed on stderr
> and the program is aborted.
>
> Setting the MALLOC_PERTURB_ environment variable causes the malloc
> functions in libc to return memory which has been wiped and clear
> memory when it is returned.
> Of course this does not affect calloc which always does clear the memory.
>
> The reason for this exercise is, of course, to find code which uses
> memory returned by malloc without initializing it and code which uses
> code after it is freed. valgrind can do this but it's costly to run.
> The MALLOC_PERTURB_ exchanges the ability to detect problems in 100%
> of the cases with speed.
>
> The byte value used to initialize values returned by malloc is the byte
> value of the environment value. The value used to clear memory is the
> bitwise inverse. Setting MALLOC_PERTURB_ to zero disables the feature.
>
> This technique can find hard to detect bugs.
> It is therefore suggested to always use this flag (at least temporarily)
> when testing out code or a new distribution.
>
> Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
> ---
> t/test-lib.sh | 6 ++++++
> 1 file changed, 6 insertions(+)
Interesting, but it bothers me to make it enabled unconditionally.
At least, this shouldn't be enabled under GIT_TEST_OPTS=--valgrind, no?
By the way, "export VAR=VAL" all on the same line, even though it is
in POSIX.1, is reported to be unsupported by some shells people care
about, and needs to be corrected to "VAR=VAL" and "export VAR" as
separate commands. I think we saw a patch to fix an instance or two
that snuck in recently.
>
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index 78c4286..98c90b0 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -93,6 +93,12 @@ export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
> export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
> export EDITOR
>
> +# Add libc malloc_check and MALLOC_PERTURB test
> +export MALLOC_CHECK_=3
> +export MALLOC_PERTURB_="$( expr \( $$ % 255 \) + 1)"
> +#
> +
> +
> # Protect ourselves from common misconfiguration to export
> # CDPATH into the environment
> unset CDPATH
next prev parent reply other threads:[~2012-09-12 17:52 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-12 12:17 [PATCH] Add MALLOC_CHECK_ and MALLOC_PERTURB_ libc env to the test suite for detecting heap corruption Elia Pinto
2012-09-12 17:51 ` Junio C Hamano [this message]
2012-09-13 16:36 ` Elia Pinto
2012-09-13 17:46 ` Junio C Hamano
-- strict thread matches above, loose matches on Subject: below --
2012-09-14 16:54 Elia Pinto
2012-09-14 17:51 ` Junio C Hamano
2012-09-14 23:18 ` Junio C Hamano
2012-09-17 12:17 ` Elia Pinto
2012-09-17 20:28 ` Junio C Hamano
2012-09-18 4:22 ` Elia Pinto
2012-09-26 20:16 ` René Scharfe
2012-09-27 6:39 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vy5kfceod.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitter.spiros@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).