接上一个程序我添加了一个东西
void ceshi(const char * input)
{
char buf[10];
strcpy(buf,input); //有问题的语句
printf("我什么时候执行了,你猜到了吗?");
}
现在给出一个模型,答案应该知晓了。
/------------------\ lower
| | memory
| Text | addresses
| |
|------------------|
| (Initialized) |
| Data |
| (Uninitialized) |
|------------------|
| |
| Stack | higher
| | memory
\------------------/ addresses
Fig. 1 Process Memory Regions
bottom of top of
memory memory
buffer sfp ret *str
<------ [ ][ ][ ][ ]
top of bottom of
stack stack
这两个图形,第一个是程序执行是在内存中的模型
第二个是调用函数是 在堆栈中的模型。ret是调用函数的返回地址,
这篇文章一定要仔细的读一读《Smashing The Stack For Fun And Profit》
http://insecure.org/stf/smashstack.html
读完之后,就非常明白了,哈哈哈哈哈哈哈哈哈
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步