所以我有这段简单的代码,演示了一个简单的缓冲区溢出:
#include <stdio.h>
int main(void)
{
char c[4] = { 'A', 'B', 'C', 'D' };
char d[4] = { 'W', 'X', 'Y', 'Z' };
printf("c[0] is '%c'\n", c[0]);
d[4] = 'Z'; /* Overflow that overwrites c[0] */
printf("c[0] is '%c'\n", c[0]);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
$ ./a.out
c[0] is 'A'
c[0] is 'Z'
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下gcc选项编译此代码,并使用飞行颜色传递:
gcc -Wall -Wextra -Wformat=2 -Wswitch-default -Wcast-align -Wpointer-arith \
-Wbad-function-cast -Wstrict-prototypes -Winline -Wundef -Wnested-externs \
-Wcast-qual -Wshadow -Wwrite-strings -Wconversion -Wunreachable-code \
-Wstrict-aliasing=2 -ffloat-store -fno-common -fstrict-aliasing \
-Wstack-protector -fstack-protector-all -std=c99 -pedantic -O0 -ggdb3
Run Code Online (Sandbox Code Playgroud)
我也试过libefence和valgrind.我希望libefence能够通过,因为它是为了捕获堆上的读/写读取/写入,但我很惊讶valgrind通过了.
此代码不会产生Segfault,因为c [4]和d [0]碰巧重叠,我认为这是导致工具错过它.
那么,是什么在那里CAN抓住这个?在Linux上运行的免费东西会很好.