I am attempting to cause a simple stack buffer overflow in the C language. This is the code I have:
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]){
char buffer[10];
strcpy(buffer,argv[1]);
};
When I run this code I use the input "0123456789" a total of 10 bytes and I recieve an error that the core was dumped. But I thought since I defined a buffer of size 10 any input greater than 10 would deliver that error, inputs less than 10 shouldn't.
I tried putting in "12345678" and this was fine so it seems like the buffer flow error occurs after 8 bytes even though the buffer is declared to be the size of 10.
Can someone help explain to me why this is the case?
There is no problem in the program. It is running perfectly.
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]){
char buffer[10];
strcpy(buffer,argv[1]);
printf("%s\n\n", buffer);
return 0;
};
OUTPUT:
Get Answers For Free
Most questions answered within 1 hours.