- 論壇徽章:
- 0
|
程序一
#include
#include
int overflow(char *buf)
{
char output[8];
strcpy(output,buf);
printf("buf的地址是:%p\n",buf);
printf("output內(nèi)容為:%s\n",output);
return 0;
}
int main()
{
char buf[26];
for(int j=0;j<26;j++)
{
buf[j]=97+j%10;
}
overflow(buf);
return 0;
}
程序二
#include
#include
int overflow(char *buf)
{
char output[8];
strcpy(output,buf);
printf("buf的地址是:%p\n",buf);
printf("output內(nèi)容為:%s\n",output);
return 0;
}
int main()
{
char buf[26];
for(int j=0;j<26;j++)
{
buf[j]=97+j/10;
}
overflow(buf);
return 0;
}
執(zhí)行后程序一和程序二的溢出出錯的地址分別為0x66656463和0x62626262
能不能給解釋一下下面這段話的意思
現(xiàn)在根據(jù)這兩個地址來確定溢出點:第二步中由于是10個字符一循環(huán)的字符串,而其最末尾的溢出地址為0x63,而我們起始循環(huán)字符為0x61(十進(jìn)制97),因此推算溢出點位置的尾數(shù)為0x63-0x61=2;第三步中,我們是逢10變換字符的,所得的出錯地址落在0x62(十進(jìn)制98)區(qū)間內(nèi),即在0x62-0x61=1段內(nèi)。因此我們推算溢出點位置在第10×1+2=12字符處。
謝謝 |
|