C buffer overflow not working

I was messing around with the buffers to gain some experience with buffer overflows but this seems not to work with me when I execute these commands from the command line:
 
./overflow_example $(perl -e 'print "A"x20 . "ABCD"')



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[]) {
	int value = 5;
	char buffer_one[8], buffer_two[8];

	strcpy(buffer_one, "one"); /* put "one" into buffer_one */
	strcpy(buffer_two, "two"); /* put "two" into buffer_two */
	
	printf("[BEFORE] buffer_two is at %p and contains \'%s\'\n", buffer_two, buffer_two);
	printf("[BEFORE] buffer_one is at %p and contains \'%s\'\n", buffer_one, buffer_one);
	printf("[BEFORE] value is at %p and is %d (0x%08x)\n", &value, value, value);

	printf("\n[STRCPY] copying %d bytes into buffer_two\n\n",  (int)strlen(argv[1]));
	strcpy(buffer_two, argv[1]); /* copy first argument into buffer_two */

	printf("[AFTER] buffer_two is at %p and contains \'%s\'\n", buffer_two, buffer_two);
	printf("[AFTER] buffer_one is at %p and contains \'%s\'\n", buffer_one, buffer_one);
	printf("[AFTER] value is at %p and is %d (0x%08x)\n", &value, value, value);
}


I am expecting the buffer_two to over flow and affect buffer_one content but after running nothing is happening and only the value of buffer_two is changing.
Last edited on
Compiler is free to place your char buffers in memory as it likes. You can try to overflow buffer_one instead. If it does not work, pring addresses of both buffer to see where they are located.
It worked fine when I overflowed buffer_one, and the value in buffer_two got affected
Topic archived. No new replies allowed.