Codesample with bufferoverflow (gets method). Why does it not behave as expected?
- by citronas
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?