Was reading through some text and playing around with attempting to write past the size of an array in C i.e buffer overflow. The text indicates that whenever you attempt to write to say array[5] when the length of the array is 5 then you get a segmentation fault but I dont seem to be getting that When using the code below. The code actually runs.
#include <stdio.h>
#include <string.h>
int main ()
{
int i;
int array[5] = {1, 2, 3, 4, 5};
for (i = 0; i <= 255; i++)
{
array[i] = 10;
}
int len = sizeof(array) / sizeof(int);
printf("%d\n", len);
printf("%d\n", array[254]);
}
On execution of the last statement, a 10 is printed. Am wondering whether this is a vulnerability or if there is something I am missing. I am running the code from iterm2 on a macbook pro.