-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbof1.c
More file actions
36 lines (29 loc) · 927 Bytes
/
bof1.c
File metadata and controls
36 lines (29 loc) · 927 Bytes
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
35
36
/*
* bof1.c
* This program was written for the purpose of demonstrating simple buffer
* overflows using an on-stack buffer and the gets() function.
*
* Suggested compiler settings; if <c compiler> is your C compiler program,
* compile this program into an executable with:
* $ <c compiler> -Wall -o bof1 bof1.c
*
* Author: Grond <grond66@foothillstemclubs.org>
*/
#include <stdio.h>
int main(void) {
int x = 5;
char buffer[100];
// print the prompt. fflush() is called to ensure that the prompt is
// actually sent to the screen, since the prompt doesn't contain a
// newline.
printf("What do you say? ");
fflush(stdout);
// let the user type one line and submit it by pressing <ENTER>
gets(buffer);
// this turns out to be very dangerous
// tell the user what they just typed
printf("You said %s\n", buffer);
// print the value of x. does it _have_ to be 5?
printf("x = %d\n", x);
return 0;
}