[问题]对一个C程序的讨论
发表于 : 2007-07-22 10:56
学校科协上学期讲了缓冲区溢出,后来我照着例子编了一个程序:
#include <stdio.h>
#include <string.h>
int main(void)
{ char largebuff[]="1234512345123451234512345===ABCD";
char smallbuff[16];
strcpy (smallbuff,largebuff);
printf(smallbuff);
}
然后用GCC编译,运行后显示缓冲区溢出,但后来用GDB分析时却出了问题,
(gdb) r
Starting program: /home/hui/a.out
*** stack smashing detected ***: /home/hui/a.out terminated
1234512345123451234512345===ABCD
Program received signal SIGABRT, Aborted.
0xffffe410 in __kernel_vsyscall ()
(gdb) i reg
eax 0x0 0
ecx 0x1ab1 6833
edx 0x6 6
ebx 0x1ab1 6833
esp 0xbff19ec8 0xbff19ec8
ebp 0xbff19ee0 0xbff19ee0
esi 0xbff19f80 -1074684032
edi 0xb7f54ff4 -1208659980
eip 0xffffe410 0xffffe410 <__kernel_vsyscall+16>
eflags 0x246 [ PF ZF IF ]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x33 51
本来此时的EIP应该为0x44434241可这里不是,
后来怀疑是GCC选项的问题,又用了-mpreferred-stack-boudery=4(按16字节对齐)还是没用。不知道是什么原因。
难道现在的GCC加了防溢出机制?请教个位高人。
#include <stdio.h>
#include <string.h>
int main(void)
{ char largebuff[]="1234512345123451234512345===ABCD";
char smallbuff[16];
strcpy (smallbuff,largebuff);
printf(smallbuff);
}
然后用GCC编译,运行后显示缓冲区溢出,但后来用GDB分析时却出了问题,
(gdb) r
Starting program: /home/hui/a.out
*** stack smashing detected ***: /home/hui/a.out terminated
1234512345123451234512345===ABCD
Program received signal SIGABRT, Aborted.
0xffffe410 in __kernel_vsyscall ()
(gdb) i reg
eax 0x0 0
ecx 0x1ab1 6833
edx 0x6 6
ebx 0x1ab1 6833
esp 0xbff19ec8 0xbff19ec8
ebp 0xbff19ee0 0xbff19ee0
esi 0xbff19f80 -1074684032
edi 0xb7f54ff4 -1208659980
eip 0xffffe410 0xffffe410 <__kernel_vsyscall+16>
eflags 0x246 [ PF ZF IF ]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x33 51
本来此时的EIP应该为0x44434241可这里不是,
后来怀疑是GCC选项的问题,又用了-mpreferred-stack-boudery=4(按16字节对齐)还是没用。不知道是什么原因。
难道现在的GCC加了防溢出机制?请教个位高人。