我寫了這個簡單的代碼進行測試緩衝區溢出:堆棧內容克++ 4.8
#include <stdio.h>
#include <string.h>
using namespace std;
int f(int x, int y, char *s){
char buf[4];
strcpy(buf,s);
return 0;
}
int main(int argc, char** argv){
f(2,3,argv[1]);
return 0;
}
然後編譯和用gdb觀看它的執行(克++ 4.8.4)
g++ -g -fno-stack-protector -o bo bo.c
gdb bo
...
b f
r "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
p $rbp // 0x7fffffffdc90
p $rsp // 0x7fffffffdc70
x/20xw $rsp
0x7fffffffdc70: 0xffffe0ef 0x00007fff 0x00000003 0x00000002
0x7fffffffdc80: 0xffffdcb0 0x00007fff 0x00000000 0x00000000
0x7fffffffdc90: 0xffffdcb0 0x00007fff 0x00400585 0x00000000
0x7fffffffdca0: 0xffffdd98 0x00007fff 0x00000000 0x00000002
0x7fffffffdcb0: 0x00000000 0x00000000 0xf7a36ec5 0x00007fff
我的理解是堆棧向下增長爲到更低的地址,但它看起來這個堆棧幀(從0x7fffffffdc90 - 0x7fffffffdc90
)向上增長:參數被向上推(s,y然後x)。這是爲什麼?
看起來像是先返回地址(0x00400585)。但接下來的話是什麼意思?他們是:
- 已保存
$rbp$
? - 接下來的2個單詞是什麼?
您不是在使用Sys V AMD64 ABI嗎? –
我該如何檢查? – user1734905
不要混淆堆棧的管理方式(push/pop)如何處理GDB的表示; e * x * amine命令將始終按升序打印地址。 –