call stack and stack buffer overflow

http://en.wikipedia.org/wiki/Call_stack

http://en.wikipedia.org/wiki/Stack_buffer_overflow 

 

Stack_buffer_overflow里提到的frame pointer 的位置不一样,不同的系统实现应该是不一样的。

运行时的栈是从高地址向低地址分配的,堆是从低地址向高地址分配的,如:


 1int main() {
 2    int a;
 3    int b;
 4    int *pc = new int;
 5    int *pd = new int;
 6    printf("%x\n"&a);//栈地址
 7    printf("%x\n"&b);//栈地址
 8    printf("%x\n"&pc);//栈地址
 9    printf("%x\n"&pd);//栈地址
10    printf("%x\n", pc);//堆地址
11    printf("%x\n", pd);//堆地址
12    return 0;
13}

 结果类似是这样的:

120fa58
220fa4c
320fa40
420fa34
5354bb8
6354bf8

update Apr. 26, 2011:

apue 2nd 7.6. Memory Layout of a C Program:

The stack grows from higher-numbered addresses to lower-numbered addresses on this particular architecture(x86).

posted on 2009-10-28 19:25  lbsx  阅读(399)  评论(0编辑  收藏  举报