stack smashing detected报错
来源:互联网 发布:阿里云域名绑定 编辑:程序博客网 时间:2024/05/02 13:34
使用环境:ubuntu 11.10、C++
出错情景:
使用mysql执行一个query语句,以进行一个涉及多个表的联合查询(query语句比较长)
代码如下:
- char query[128]={0};
- sprintf(query, ".....");
- ...
- return myList;
- #include <stdio.h>
- void func()
- {
- char array[10];
- gets(array);
- }
- int main(int argc, char **argv)
- {
- func();
- }
-fno-stack-protector
In that case you will get a segmentation fault if you try to access illegal memory location. and of course you can detect the point of overflow say for example using using valgrind.
但是,在执行完return语句时,弹出该错误:“** stack smashing detected ***:a.o terminated”
寻找原因:
问题很奇怪,在return的时候返回,按说应该是正常的执行,没什么问题的呀。。。
在网上查到类似的错误不多,但找到一篇很有用的:http://stackoverflow.com/questions/1345670/stack-smashing-detected
原文如下:
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的一种检测“缓存溢出”的保护机制
并举例:如果在gets(array); 中,输入多于10个char,就会导致stack smashing错误
问题解决:
由于query语句比较长,所以也没检查char query[128]是否够用
在修改了query字符数组的长度为255之后,发现问题解决...
小结:
不只是在Linux下,在Windows下也有同样的状况。当分配的内存不够时,会继续执行;但是在程序结束返回时才出现错误提示。
- stack smashing detected报错
- stack smashing detected
- [error]stack smashing detected
- *** stack smashing detected ***
- Stack smashing detected
- *** stack smashing detected ***与GCC “stack smashing detected”机制
- *** stack smashing detected ***: 程序错误
- *** stack smashing detected ***: ./braodcast_udp terminated
- stack smashing detected 的处理
- stack smashing detected错误解决
- GCC关闭Stack-Smashing Protecto(stack smashing detected)
- GCC关闭Stack-Smashing Protecto(stack smashing detected) zz
- stack smashing detected 错误的处理
- stack smashing detected问题的一个原因
- stack smashing detected,程序段错误
- [2017/2/24]stack smashing detected问题
- stack溢出 ** stack smashing detected ***: ./a.out terminated
- 分配空间不足引起的错误:‘Stack smashing detected’
- 图的遍历方法(深度优先和广度优先算法)
- Tomcat监控xml ,当修改xml后,不用重启tomcat
- java中的复制文件
- 关于ListView中ViewHolder修饰符的问题
- 菜鸟学习OpenCV(Python)碰到的一些小问题
- stack smashing detected报错
- 黑马程序员——Java反射&动态代理
- hdu 2141 Can you find it? 二分
- 关于嵌入式处理器的基础知识归纳
- Uinty3D Rigidbody刚体及 Colliders 碰撞体
- Swap Nodes in Pairs
- leetcode239:Sliding Window Maximum
- 2.1 Python是如何进行内存管理的?
- 陈力:传智播客古代 珍宝币 泡泡龙游戏开发第九讲:块元素、行内元素、标准流、盒子模型