stack smashing detected,程序段错误
2016-12-15 16:47
441 查看
今天在写程序的时候,突然出现"stack smashing detected"的错误.用经常用的调试方法,GDB,语句输出等均不能定位问题的出处.
先说解决方案:
出现这个问题的原因是:在程序函数中,数组越界访问,在程序运行时没出现问题,但当函数return的时候就会出现上面的错误.
解决办法是:gdb, where命令定位到出错的函数,然后检查函数中数组的长度,使其满足程序的要求.
参考了文档(http://stackoverflow.com/questions/1345670/stack-smashing-detected)上面的描述:
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:
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.
To get some insight, you can try disabling this protection of gcc using option
always be turned on for release builds as it is a security feature.
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.
Stack Smashing is actually a protection mechanism used by gcc to detect buffer overflow attacks.
An input of string greater than size 10 causes corruption of gcc inbuilt protection canary variable followed by SIGABRT to terminate
the program.You can disable this protection of gcc using option即:stack
smashing是GCC的一种检测“缓存溢出”的保护机制.当分配的内存不够时,会继续执行;但是在程序结束返回时才出现错误提示
先说解决方案:
出现这个问题的原因是:在程序函数中,数组越界访问,在程序运行时没出现问题,但当函数return的时候就会出现上面的错误.
解决办法是:gdb, where命令定位到出错的函数,然后检查函数中数组的长度,使其满足程序的要求.
参考了文档(http://stackoverflow.com/questions/1345670/stack-smashing-detected)上面的描述:
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(); }
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.
To get some insight, you can try disabling this protection of gcc using option
-fno-stack-protectorwhile 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-protectorshould
always be turned on for release builds as it is a security feature.
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.
Stack Smashing is actually a protection mechanism used by gcc to detect buffer overflow attacks.
An input of string greater than size 10 causes corruption of gcc inbuilt protection canary variable followed by SIGABRT to terminate
the program.You can disable this protection of gcc using option即:stack
smashing是GCC的一种检测“缓存溢出”的保护机制.当分配的内存不够时,会继续执行;但是在程序结束返回时才出现错误提示
相关文章推荐
- vue概念及基础学习
- 内存测试分享文档
- 面向对象的设计模式
- dev LayoutControl布局控件
- 边框、内阴影、背景图片、背景颜色、外阴影的呈现级别
- Mysql学习(四)
- block 什么时候需要构造循环引用
- LeetCode #226 - Invert Binary Tree - Easy
- spring annotation 注入static 属性
- JAVA远程连接linux服务器读取文件(JSch)
- MySql中利用insert into select 准备数据uuid主键冲突
- 利用Application 存储全变量
- springboot CGLib 方式实现AOP代理问题
- [kpw] Kindle Paperwhite被强制升级到5.6.5后,USBNetwork无法使用
- OpenCV: Canny边缘检测算法原理及其VC实现详解(转载)
- ORACLE中STATUS为INACTIVE但是SERVER为SHARED状态的会话浅析
- grep
- 第五章 引用类型 Function 类型
- 在css嵌套中的html的table里的字左右不对齐
- iOS之应用程序国际化