我正在尝试测试缓冲区溢出示例。
以下是我尝试使用文件名buffOVF.c进行编译的代码:
#include <stdlib.h>
#include <string.h>
int main(void)
{
//stack corruption
char buf2[16] = "overwriteme";
//slightly less than 16 bytes but it doesn't matter
char buf1[16];
//uninitialized
strcpy(buf1, "1234567890123456789");
//buffer contains 16 bytes, I've input 19 (overflow of 4 due to null ptr at end of string)
//writing to buf1
printf("buf1 val: %s\n", buf1);
printf("buf2 val: %s\n", buf2);
printf("buf1 addr: %p\n", (void *)buf1);
printf("buf2 addr: %p\n", (void *)buf2);
// TO RUN : gcc -o bufferOVF. bufferOVF.c -fno-stack-protector && clear && ./bufferOVF.
return 0;
}
我正在尝试使用以下命令在带有OSX 10.14的Macbook Pro上对此进行编译:
clang -o buffOVF. buffOVF.c -fno-stack-protector
现在,我尝试在没有堆栈保护的情况下运行此,以便可以看到溢出发生。但是,这不会发生,因为我一直将其作为输出:
Abort trap: 6
为什么会这样?我已经做了大量研究,但找不到解决该特定问题的任何方法。
答案 0 :(得分:3)
为什么会这样?
发生这种情况是因为,嗯,您溢出了缓冲区!
这实际上是您要观察的:缓冲区溢出时会发生什么。
结果可能会有所不同,就像行为不确定时一样。
停止缓冲区溢出。