为什么我不能禁用堆栈保护?

Why can't I disable stack protection?

我现在用的OS是64位Ubuntu14.04,gcc版本是4.8.4。

我写了一个如下所示的简单程序来做一些与缓冲区溢出相关的测试,不知何故我发现我无法正常溢出本地字符串。

/*test.c*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int bof(char *str)
{
    char buffer[4];
    strcpy(buffer, str);
    return 1;
}

int main()
{
    char str[]="123456789012345'; 

    /* This is the maximum length the string
     can be, which is 16 bytes including the null character at the end, and 
    any strings that are longer than this would result in a segmentation fault */

    bof(str);
}

这个程序是用命令

编译的
gcc -o test -fno-stack-protector test.c

所以应该禁用堆栈保护。

根据我的观察,任何长度小于或等于16个字符(包括空字符)的字符串都可以;否则,它会导致分段错误。

有什么想法为什么以及如何让它发挥作用吗?提前致谢!

你可以使用GNU Debug来查找距离,这里有一个教程http://www.cs.umd.edu/~srhuang/teaching/cmsc212/gdb-tutorial-handout.pdf