Codesample with bufferoverflow (gets method). Why does it not behave as expected?
Posted
by citronas
on Stack Overflow
See other posts from Stack Overflow
or by citronas
Published on 2010-06-08T19:25:23Z
Indexed on
2010/06/08
19:32 UTC
Read the original article
Hit count: 226
This an extract from an c program that should demonstrate a bufferoverflow.
void foo()
{
char arr[8];
printf(" enter bla bla bla");
gets(arr);
printf(" you entered %s\n", arr);
}
The question was "How many input chars can a user maximal enter without a creating a buffer overflow"
My initial answer was 8, because the char-array is 8 bytes long. Although I was pretty certain my answer was correct, I tried a higher amount of chars, and found that the limit of chars that I can enter, before I get a segmentation fault is 11. (Im running this on A VirtualBox Ubuntu)
So my question is: Why is it possible to enter 11 chars into that 8 byte array?
© Stack Overflow or respective owner