Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Debugging &引用;gdb";及;valgrind“;以不同的方式执行二进制文件?_Debugging_Gdb_Valgrind_Heap Corruption_Memory Corruption - Fatal编程技术网

Debugging &引用;gdb";及;valgrind“;以不同的方式执行二进制文件?

Debugging &引用;gdb";及;valgrind“;以不同的方式执行二进制文件?,debugging,gdb,valgrind,heap-corruption,memory-corruption,Debugging,Gdb,Valgrind,Heap Corruption,Memory Corruption,我的程序在堆内存损坏方面出错 osboxes@osboxes:/mnt/hgfs/VM_Shared/ISSUES/_[02]$ ./shuf /dev/null *** Error in `./shuf': corrupted double-linked list: 0xb7f01ac0 *** 在仅使用gdb进行调试时,我遇到了valgrind。(感谢) 而且…我使用valgrind获取日志 (很抱歉日志太长,我本来想在提问前将其缩写,但我担心可能会遗漏一些分析所需的信息。) 问

我的程序在堆内存损坏方面出错

osboxes@osboxes:/mnt/hgfs/VM_Shared/ISSUES/_[02]$ ./shuf /dev/null
*** Error in `./shuf': corrupted double-linked list: 0xb7f01ac0 ***


在仅使用gdb进行调试时,我遇到了
valgrind
。(感谢)
而且…我使用
valgrind
获取日志

(很抱歉日志太长,我本来想在提问前将其缩写,但我担心可能会遗漏一些分析所需的信息。)



问题:

valgrind
无效读取发生在文件opc.c的
178行

然而,我发现这个程序在被
gdb
调试时从未进入fileopc.c中的
178行
控制流以不同的方式运行,如下所示

pwndbg> 
176 in fileops.c
────────────────────────────[ DISASM ]────────────────────────────
   0xb7e7184f <_IO_file_close_it+63>     mov    edx, dword ptr [ebx + 0x68]
   0xb7e71852 <_IO_file_close_it+66>     test   edx, edx
 > 0xb7e71854 <_IO_file_close_it+68>   ✔ jle    _IO_file_close_it+151 <0xb7e718a7>
    ↓
   0xb7e718a7 <_IO_file_close_it+151>    push   0
   0xb7e718a9 <_IO_file_close_it+153>    push   0
   0xb7e718ab <_IO_file_close_it+155>    push   0


pwndbg> 
185 in fileops.c
────────────────────────────[ DISASM ]────────────────────────────
   0xb7e7184f <_IO_file_close_it+63>     mov    edx, dword ptr [ebx + 0x68]
   0xb7e71852 <_IO_file_close_it+66>     test   edx, edx
   0xb7e71854 <_IO_file_close_it+68>     jle    _IO_file_close_it+151 <0xb7e718a7>
    ↓
 > 0xb7e718a7 <_IO_file_close_it+151>    push   0
   0xb7e718a9 <_IO_file_close_it+153>    push   0
   0xb7e718ab <_IO_file_close_it+155>    push   0
pwndbg>
176 in fileops.c
────────────────────────────[DISASM]────────────────────────────
0xb7e7184f mov edx,dword ptr[ebx+0x68]
0xb7e71852测试edx,edx
>0xb7e71854✔ jle\u IO\u文件\u关闭\u it+151
↓
0xb7e718a7推送0
0xb7e718a9推送0
0xb7e718ab推送0
pwndbg>
185 in fileops.c
────────────────────────────[DISASM]────────────────────────────
0xb7e7184f mov edx,dword ptr[ebx+0x68]
0xb7e71852测试edx,edx
0xb7e71854 jle\u IO\u文件\u关闭\u it+151
↓
>0xb7e718a7推送0
0xb7e718a9推送0
0xb7e718ab推送0

问题(续):

正如您所看到的,控制流没有到达fileopc.c
中的
178行,其中
valgrind
指出了嵌套的bug。
相反,控制流只是直接从fileops.c中的
176跳到fileops.c中的
185


问题:

这里发生了什么事? 为什么
valgrind
gdb
之间的控制流不同?
是因为这两个工具在生成被检查的程序时使用了不同的方法吗?

这里发生了什么事

发件人:

程序在Valgrind上运行正常,但在退出时会产生一系列涉及u libc_freeres的错误,然后由于分段错误而终止。

当程序退出时,Valgrind在glibc中运行程序_libc_freeres。这是内存调试器的一个钩子,因此他们可以要求glibc释放它所使用的任何内存。这样做是为了确保Valgrind不会错误地报告glibc中的空间泄漏

问题是,在较旧的glibc版本中运行u libc_freeres会导致此崩溃

Valgrind 1.1.X及更高版本的变通方法:使用--run libc freeres=no选项。然后,您可能会收到glibc分配的空间泄漏报告(请不要向glibc人员报告这些,因为它们不是真正的泄漏),但至少程序会运行

请注意,尽管上面的文本讨论的是较旧的GLIBC,但这也可能发生在损坏GLIBC内部状态的程序中,这里显然就是这种情况

为什么valgrind和gdb之间的控制流不同


GDB不调用
\u libc\u freeres
,Valgrind调用。(还有许多其他细微的差别,但这一点最有可能解释所观察到的碰撞。)

谢谢您的建议!使用
--run libc freers=no
选项,我可以消除第二个错误,这是关于u libc_freeres的。(编辑了上面的日志)但是,我仍然不知道我在问题中提到的关于
fileops.c:178的无效读取问题。。。尽管这个问题与glibc-freer无关(可以在上面的调用堆栈中看到),但控制流与
gdb
。。。这是否是valgrind上的另一个问题?
pwndbg> 
176 in fileops.c
────────────────────────────[ DISASM ]────────────────────────────
   0xb7e7184f <_IO_file_close_it+63>     mov    edx, dword ptr [ebx + 0x68]
   0xb7e71852 <_IO_file_close_it+66>     test   edx, edx
 > 0xb7e71854 <_IO_file_close_it+68>   ✔ jle    _IO_file_close_it+151 <0xb7e718a7>
    ↓
   0xb7e718a7 <_IO_file_close_it+151>    push   0
   0xb7e718a9 <_IO_file_close_it+153>    push   0
   0xb7e718ab <_IO_file_close_it+155>    push   0


pwndbg> 
185 in fileops.c
────────────────────────────[ DISASM ]────────────────────────────
   0xb7e7184f <_IO_file_close_it+63>     mov    edx, dword ptr [ebx + 0x68]
   0xb7e71852 <_IO_file_close_it+66>     test   edx, edx
   0xb7e71854 <_IO_file_close_it+68>     jle    _IO_file_close_it+151 <0xb7e718a7>
    ↓
 > 0xb7e718a7 <_IO_file_close_it+151>    push   0
   0xb7e718a9 <_IO_file_close_it+153>    push   0
   0xb7e718ab <_IO_file_close_it+155>    push   0