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

Re: [RFC 2/2] Make misuse of get_pathname() buffers detectable by valgrind

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
Nov 16, 2011, 13:57 UTC
Message-ID
<CACsJy8CG0A1kUUyA=1AW+3cNTjrgb_iKjdfs7M8Sa6s0cuDANw@mail.gmail.com>
In-Reply-To
<1317097687-11098-3-git-send-email-mhagger@alum.mit.edu>
On Tue, Sep 27, 2011 at 11:28 AM, Michael Haggerty <mhagger@alum.mit.edu> wrote:
Show 20 quoted lines
> A temporary buffer produced by get_pathname() is recycled after a few
> subsequent calls of get_pathname().  The use of such a buffer after it
> has been recycled can result in the wrong file being accessed with
> very strange effects.  Moreover, such a bug can lie dormant until code
> elsewhere is changed to use a temporary buffer, causing very
> mysterious, nonlocal failures that are hard to analyze.
>
> Add a second implementation of get_pathname() (activated if the
> VALGRIND preprocessor macro is defined) that allocates and frees
> buffers instead of recycling statically-allocated buffers.  This does
> not make the problem less serious, but it turns the errors into
> access-after-free errors, making it possible to locate the guilty code
> using valgrind.
>
> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
> ---
>
> I believe that it is frowned upon to use #ifdefs in git code, but no
> good alternative is obvious to me for this type of use.  Suggestions
> are welcome.

Enable the code based on an environment variable, e.g. GIT_DEBUG_FENCE, then enable it by default in test-lib.sh :-)

-- 
Duy
Previous: Michael HaggertyNext: Nguyen Thai Ngoc Duy
Message 4 of 5 in “[RFC 0/2] Debugging tools for get_pathname()”
  1. Michael HaggertySep 27, 2011
  2. 1/2 Make the number of pathname buffers a compile-time constantMichael Haggerty, Sep 27, 2011
  3. 2/2 Make misuse of get_pathname() buffers detectable by valgrindMichael Haggerty, Sep 27, 2011
  4. Nguyen Thai Ngoc DuyNov 16, 2011
  5. Nguyen Thai Ngoc DuyNov 16, 2011

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.