So here I believe I have a small buffer overflow problem I found when reviewing someone else\'s code. It immediately struck me as incorrect, and potentially dangerous, but a
I tried it with heap allocations, variables are not continuous in memory in this case. That is why it is hard to make buffer overflow in this case.
Buy try it with stack overflow
#include "stdio.h"
#include "string.h"
int main()
{
unsigned int y = (0xFFFFFFFF);
char buffer[strlen("This string is 27 char long" + 1)];
unsigned int x = (0xFFFFFFFF);
sprintf(buffer, "This string is 27 char long");
printf("X (%#x) is %#x, Y (%#x) is %#x, buffer '%s' (%#x) \n", &x, x,&y, y, buffer, buffer);
return 0;
}
You will see that Y is corrupted.