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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Sep 27, 2011 at 11:28 AM, Michael Haggerty <mhagger@xxxxxxxxxxxx> wrote:
> +#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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]