分配空间不足引起的错误:‘Stack smashing detected’
来源:互联网 发布:知无涯者电影下载 编辑:程序博客网 时间:2024/04/26 22:14
使用环境:ubuntu 11.10、C++
出错情景:
使用mysql执行一个query语句,以进行一个涉及多个表的联合查询(query语句比较长)
代码如下:
char query[128]={0};sprintf(query, ".....");...return myList;执行结束之后,返回一个list类型的值
#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’
- 分配空间不足引起的错误:‘Stack smashing detected’
- 分配空间不足引起的错误:‘Stack smashing detected’
- stack smashing detected 错误的处理
- *** stack smashing detected ***: 程序错误
- stack smashing detected错误解决
- stack smashing detected 的处理
- stack smashing detected,程序段错误
- 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 ***: ./braodcast_udp terminated
- stack smashing detected报错
- c语言学习之分配不足引起的错误
- 开发技巧
- 10分钟学会 Cucumber + Watir 自动化测试框架
- NYOJ 491幸运三角形
- ubuntu 安装nvidia 显卡驱动
- linux 用speex库压缩音频
- 分配空间不足引起的错误:‘Stack smashing detected’
- JavaScript正则表达式
- 字体设置器(TSpinEdit、TListBox使用)
- OGRE动画实现(模型自己动)
- 模仿launcher的效果
- Android 监听系统启动完毕事件
- latex 设置multirow模板
- webservice 测试窗体只能用于来自本地计算机的请求 .
- 幻数