スタックが破損したときに何が起こるかを理解しようとしています。これは私が理解しようとしたサンプルプログラムです。バッファのサイズを 1 バイトと定義しました。しかし、13 バイト目に入るとスタックの破損が発生します。13 バイト目以降が破損するのはなぜですか?
C コード :
#include<stdio.h>
#include<string.h>
int main(int argc,char *argv[]){
char buffer[1];
strcpy(buffer,argv[1]);
printf("\n buffer : %s \n",buffer);
return 0;
}
アセンブリ コード :
.file "buffer_overflow.c"
.section .rodata
.LC0:
.string "\n buffer : %s \n"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $32, %esp
movl 12(%ebp), %eax
addl $4, %eax
movl (%eax), %eax
movl %eax, 4(%esp)
leal 31(%esp), %eax
movl %eax, (%esp)
call strcpy
movl $.LC0, %eax
leal 31(%esp), %edx
movl %edx, 4(%esp)
movl %eax, (%esp)
call printf
movl $0, %eax
leave
ret
.size main, .-main
.ident "GCC: (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5"
.section .note.GNU-stack,"",@progbits