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, 14:18 UTC
Message-ID
<CACsJy8BK3zvxA5mpC+3UvYMe20X6iFWJ7JL+VH6fr-Xstw2usg@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 18 quoted lines
> +#ifdef VALGRIND
> +       static char *pathname_array[PATHNAME_BUFFER_COUNT];
> +       index = (index + 1) & (PATHNAME_BUFFER_COUNT - 1);
> +       if (pathname_array[index]) {
> +               /*
> +                * In a correct program, this will have no effect, but
> +                * *if* somebody erroneously uses this buffer after it
> +                * has been freed, it gives more of a chance that the
> +                * error will be detected even if valgrind is not
> +                * running:
> +                */
> +               strcpy(pathname_array[index], buggy_path);
> +
> +               free(pathname_array[index]);
> +       }
> +       pathname_array[index] = xmalloc(PATH_MAX);
> +       return pathname_array[index];
> +#else

Not sure if it works (just read man pages, haven't tried anything) I'm thinking to use mmap() with MAP_ANONYMOUS instead of xmalloc(), then mprotect() instead of free() to remove read access from that area. Any access after that should be caught. Leaking may not be severe for git_path(), hopefully.

-- 
Duy
Previous: Nguyen Thai Ngoc Duy
Message 5 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.