分配空间不足引起的错误:‘Stack smashing detected’
来源:互联网 发布:php移动到远程 编辑:程序博客网 时间:2024/04/19 13:32
转自 : http://blog.csdn.net/xiaobai1593/article/details/7376573
出错情景:
使用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’
- 分配空间不足引起的错误:‘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语言学习之分配不足引起的错误
- 带有O(1)时间返回最小值的stack
- Quartz 2.2.1 学习笔记(三) Trigger
- 小白学开发(iOS)OC_第一个OC (与C的区别)(2015-07-21)
- 2015 Multi-University Training Contest 1 题解&&总结
- CentOS6.5 64位安装OpenVPN+Windows客户端配置
- 分配空间不足引起的错误:‘Stack smashing detected’
- md5算法代码
- “100 Best GitHub: Deep Learning”
- iOS开发,导入c文件引发的 Unknown type name 'NSString' 问题
- 小白学开发(iOS)OC_定义一个类(2015-07-21)
- Find Minimum in Rotated Sorted Array
- HDU 5289 Assignment (RMQ——ST算法)
- jquery checkbox全选功能
- iOS的主要框架介绍