开发者

squelching glibc memory corruption stack trace output

开发者 https://www.devze.com 2023-03-28 19:02 出处:网络
Is there any way to squelch the output that glibc generates when there is memory corruption? Here\'s what I\'m seeing

Is there any way to squelch the output that glibc generates when there is memory corruption? Here's what I'm seeing

make
*** glibc detected *** /home/myname/php/sapi/cli/php: free(): invalid pointer:  x0045d67f ***
======= Backtrace: =========
/lib/libc.so.6(+0x6eb41)[0x380b41]

<snip>
======= Memory map: ========
00115000-00116000 r-xp 00000000 00:00 0          [vdso]
001d7000-001ee000 r-xp 00000000 ca:01 540738     /lib/libpthread-2.12.2.so
001ee000-001ef000 r--p 00016000 ca:01 540738     /lib/libpthread-2.12.2.so
001ef000-001f0000 rw-p 00017000 ca:01 540738     /lib/libpthread-2.12.2.so
<snip>

For the work I am doing, I couldn't care less ab开发者_运维百科out this info, it only matters that the make did not succeed (return value != 0). These messages are filling up the screen and it makes the rest of my output unreadable. I have tried:

make &> /dev/null
{ make ; } &> /dev/null
x=`make 2>&1` &> /dev/null

but none of them catch the output. If it isn't being written to stderr, where the heck is it coming from? I'd like a solution that doesn't require rebuilding glibc, if possible.

Here is some code which will give such an error message, but note this has nothing to do with the code I am working on (the php source code). I just want to silence this type of output from my console.

int main()
{
    char* ptr = (char*)malloc(sizeof("test"));
    char array[]= "test";
    ptr = array;
    free(ptr);
    return 0;
}


Yes: run your code with the environment variable MALLOC_CHECK_ (the trailing underscore is deliberate) set to 0.

This is partially documented in the libc manual, although there seem to be more options than just the 0, 1 or 2 which are suggested there. (The value ends up being passed as the action argument to malloc_printerr() in glibc's malloc/malloc.c, and the default value seems to be 3.)

The reason you can't redirect it is that it gets written specifically to /dev/tty, unless you have set the environment variable LIBC_FATAL_STDERR_. (I'm not sure this is documented anywhere, but the relevant code can be found here.)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号