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 17, 2012, 20:28 UTC
Message-ID
<7vzk4otmwb.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CA+EOSBk0hN+v+PK8jzCCZgG0Ko7SsHOSB=cM7nnaSsrUOaJ-7Q@mail.gmail.com>
Elia Pinto <gitter.spiros@gmail.com> writes:
Show 12 quoted lines
>>  - That "165" thing I mentioned earlier.
>
> Thank you so much for the comments, that's fine. A single
> consideration for  MALLOC_PERTURB.
>
> You can use any value between 1..255 for MALLOC_PERTURB_
> That chooses the byte that glibc will use to memset all freed buffers.
> In general it is defined as
>
>     export MALLOC_PERTURB_=$(($RANDOM % 255 + 1))
>
> (as drepper pointed out http://udrepper.livejournal.com/11429.html)
Drepper never recommends RANDOM there.
> Using a random value is slightly better than using a fixed one
> in case your fixed value is someday just the right/wrong value to mask
> a problem.

Quite the contrary. When you use a fixed pattern, it is easy which other pieces of memory has uninitailized contents. When you use a random value, you sometimes get an error and sometimes the test mysteriously pass, which does not help debugging.

openSUSE folks seem to use a fixed value for this exact reason of repeatability of tests.

http://jaegerandi.blogspot.com/2012/01/finding-subtile-malloc-bugs.html
> So OK per the original expression?
No.

I am not convinced 165 is the perfect value, but I am fairly certain any fixed value is better than using a random to deliberately worsen repeatability of the tests.

Previous: Elia PintoNext: Elia Pinto
Message 5 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.