堆栈上的本地缓冲区和返回地址之间是什么?

时间:2016-06-03 23:55:42

标签: c stack gdb

我有一个本地char缓冲区大小为4,我填充了主argv [1]的strcpy,其中包含4个'A'字符。使用gdb我打印出我的变量和堆栈信息。然后我检查了内存内容。

(gdb) info frame
Stack level 0, frame at 0xbffff0e0:
eip = 0x804848e in main (sbov.c:12); saved eip = 0xb7e2fa83
source language c.
Arglist at 0xbffff0d8, args: argc=2, argv=0xbffff174
Locals at 0xbffff0d8, Previous frame's sp is 0xbffff0e0
Saved registers:
ebp at 0xbffff0d8, eip at 0xbffff0dc
(gdb) print &buffer
$8 = (char (*)[1]) 0xbffff0cf
(gdb) x/5xw 0xbffff0cf
0xbffff0cf: 0x41414141  0x00000000  0x00000000  0xe2fa8300
0xbffff0df: 0x000002b7
(gdb) x/32xb 0xbffff0cf
0xbffff0cf: 0x41    0x41    0x41    0x41    0x00    0x00    0x00    0x00
0xbffff0d7: 0x00    0x00    0x00    0x00    0x00    0x83    0xfa    0xe2
0xbffff0df: 0xb7    0x02    0x00    0x00    0x00    0x74    0xf1    0xff
0xbffff0e7: 0xbf    0x80    0xf1    0xff    0xbf    0xea    0xcc    0xfe

在最后一个0x41之后和0x83之前,什么是0x00?这只是额外的空间吗?

源代码

/* sbov.c */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int
main(int argc, char **argv)
{
    if (argc > 1) {
        char buffer[4];
        strcpy(buffer, argv[1]);
        fprintf(stdout, "echo: %s\n", buffer);
    }
    return 0;
}

编译器选项

gcc -ggdb -fno-stack-protector

是的,这是一个安全类,它容易出现堆栈溢出。

0 个答案:

没有答案
相关问题