stack smashing detected,程序段错误

编程入门 行业动态 更新时间:2024-10-24 20:19:14

stack smashing detected,程序段<a href=https://www.elefans.com/category/jswz/34/1771449.html style=错误"/>

stack smashing detected,程序段错误

stack smashing detected,程序段错误



今天在写程序的时候,突然出现"stack smashing detected"的错误.用经常用的调试方法,GDB,语句输出等均不能定位问题的出处.

先说解决方案:

出现这个问题的原因是:在程序函数中,数组越界访问,在程序运行时没出现问题,但当函数return的时候就会出现上面的错误.

解决办法是:gdb, where命令定位到出错的函数,然后检查函数中数组的长度,使其满足程序的要求.

参考了文档()上面的描述:

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-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.

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的一种检测“缓存溢出”的保护机制.当分配的内存不够时,会继续执行;但是在程序结束返回时才出现错误提示



参考

更多推荐

stack smashing detected,程序段错误

本文发布于:2024-03-11 16:28:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1729395.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   程序   stack   smashing   detected

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!