- 论坛徽章:
- 0
|
1.c
int main(void)
{
char * str1 = "6789";
char * str2 = "123456789";
strcpy(str1, str2);
return 0;
}
winxp gcc 3.4.2
gcc -S 1.c
1.s:
.file "1.c"
.def ___main; .scl 2; .type 32; .endef
.section .rdata,"dr"
LC0:
.ascii "6789\0"
LC1:
.ascii "123456789\0"
.text
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
pushl %ebp
movl %esp, %ebp
subl $24, %esp
andl $-16, %esp
movl $0, %eax
addl $15, %eax
addl $15, %eax
shrl $4, %eax
sall $4, %eax
movl %eax, -12(%ebp)
movl -12(%ebp), %eax
call __alloca
call ___main
movl $LC0, -4(%ebp)
movl $LC1, -8(%ebp)
movl -8(%ebp), %eax
movl %eax, 4(%esp)
movl -4(%ebp), %eax
movl %eax, (%esp)
call _strcpy
movl $0, %eax
leave
ret
.def _strcpy; .scl 3; .type 32; .endef
运行报错0x00403000无法written
str1指向了一个被分配到rodata段的地址, str2也是, 当strcpy(str1, str2)时, 往str1指向的地址写入就会报错,str1指向的是只读区域。 |
|