砸检测堆栈 [英] Stack smashing detected

查看:125
本文介绍了砸检测堆栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我执行我的a.out文件。后执行程序运行一段时间再与消息退出:

I am executing my a.out file. After execution the program runs for some time then exits with the message:

**** stack smashing detected ***: ./a.out terminated*
*======= Backtrace: =========*
*/lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x48)Aborted*

有什么能为这个可能的原因以及如何纠正我吧?

What could be the possible reasons for this and how do I rectify it?

推荐答案

堆栈溢出这里实际上是造成由于使用GCC检测缓冲区溢出错误保护机制。例如,在下面的代码片段:

Stack Smashing here is actually caused due to a protection mechanism used by gcc to detect buffer overflow errors. For example in the following snippet:

#include <stdio.h>

void func()
{
    char array[10];
    gets(array);
}

int main(int argc, char **argv)
{
    func();
}

,编译器,(在这种情况下的gcc)增加了保护变量(称为金丝雀),其具有已知的值。尺寸大于10的输入字符串导致此变量导致SIGABRT终止程序的腐败。

The compiler, (in this case gcc) adds protection variables (called canaries) which have known values. An input string of size greater than 10 causes corruption of this variable resulting in SIGABRT to terminate the program.

要得到一些见解,您可以尝试使用选项禁用这种保护的gcc -fno-堆栈保护在编译时。在这种情况下,当你试图访问一个非法的内存位置,你会得到一个不同的错误,最有可能是分段错误。需要注意的是 -fstack保护器应始终打开的发布版本,因为它是一个安全功能。

To get some insight, you can try disabling this protection of gcc using option -fno-stack-protector while compiling. In that case you will get a different error, most likely a segmentation fault as you are trying to access an illegal memory location. Note that -fstack-protector should always be turned on for release builds as it is a security feature.

您可以通过调试器中运行该程序获得有关溢出点的一些信息。 Valgrind的不堆栈相关的错误很好地工作,但像一个调试器,它可以帮助你针点坠机的地点和原因。

You can get some information about the point of overflow by running the program with a debugger. Valgrind doesn't work well with stack-related errors, but like a debugger, it may help you pin-point the location and reason for the crash.

这篇关于砸检测堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆