git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Add MALLOC_CHECK_ and MALLOC_PERTURB_ libc env to the test suite for detecting heap corruption

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 14, 2012, 17:51 UTC
Message-ID
<7v392k5w7u.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1347641662-3596-1-git-send-email-gitter.spiros@gmail.com>
Elia Pinto <gitter.spiros@gmail.com> writes:
Show 12 quoted lines
> 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.
> ...
> Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
> ---
> This the third reroll of the original patch.
Well written.  I have one suggestion and a question, though.
Show 14 quoted lines
>  t/test-lib.sh |    9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index 78c4286..f34b861 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -93,6 +93,15 @@ export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
>  export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
>  export EDITOR
>  
> +# Add libc MALLOC and MALLOC_PERTURB test 
> +# only if we are not executing the test with valgrind
> +expr "$GIT_TEST_OPTS" : ".*\(--valgrind\)" >/dev/null || {
I would write this like
	if ! expr " $GIT_TEST_OPTS " : ".* --valgrind " >/dev/null
	then
		...
	fi
> +	MALLOC_CHECK_=3
> +	export MALLOC_CHECK_
> +	MALLOC_PERTURB_="$( expr \( $$ % 255 \) + 1)"

How was this expression chosen? The only effect I can think of to use a randomly picked value here is to make it impossible to make the test repeatable and reproducible, so you must have had some benefit that outweighs the downside, but I cannot think of any. Wouldn't MALLOC_PERTURB_=165 (i.e. 0xA5, half of the bits in the byte is set, including the MSB, and is an odd number) be equally a good choice without repeatability downside, for example?

Also, doesn't the above give 256 sometimes, which would not fit in a byte?

Show 6 quoted lines
> +	export MALLOC_PERTURB_
> +}
> +
>  # Protect ourselves from common misconfiguration to export
>  # CDPATH into the environment
>  unset CDPATH
Previous: Elia PintoNext: Junio C Hamano
Message 2 of 8 in “Add MALLOC_CHECK_ and MALLOC_PERTURB_ libc env to the test suite for detecting heap corruption”
  1. Add MALLOC_CHECK_ and MALLOC_PERTURB_ libc env to the test suite for detecting heap corruptionElia Pinto, Sep 14, 2012
  2. Junio C HamanoSep 14, 2012
  3. Junio C HamanoSep 14, 2012
  4. Elia PintoSep 17, 2012
  5. Junio C HamanoSep 17, 2012
  6. Elia PintoSep 18, 2012
  7. René ScharfeSep 26, 2012
  8. Junio C HamanoSep 27, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.