接上一个程序我添加了一个东西

 

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

读完之后,就非常明白了,哈哈哈哈哈哈哈哈哈

posted on 2008-09-01 22:41  黄剑父  阅读(392)  评论(0编辑  收藏  举报