-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexploitme.c
34 lines (27 loc) · 933 Bytes
/
exploitme.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <string.h>
#define BUFSIZE 128
#define A_CONSTANT 0x42424242
void read_input() {
char buffer[BUFSIZE];
const int i_dont_change = A_CONSTANT;
printf("Tell me a message and I will say it back to you.\n");
// Read a line of input into 'buffer'
gets(buffer);
printf("You said: %s, which is located at address %p and has length %lu.\n", buffer, &buffer, strlen(buffer));
printf("The size of buffer is %i bytes.\n", BUFSIZE);
// Check for overflow
if (strlen(buffer) > BUFSIZE) {
printf("You have overflowed the buffer. Oh no!\n");
}
// Make sure that i_dont_change didn't change!
if (i_dont_change != A_CONSTANT) {
printf("i_dont_change has value %#x instead of %#x\n", i_dont_change, A_CONSTANT);
}
}
void goal_function() {
printf("If you caused the program to call this function, you win!\n");
}
int main() {
read_input();
}