-
Notifications
You must be signed in to change notification settings - Fork 0
/
bufferoverflow.c
29 lines (22 loc) · 925 Bytes
/
bufferoverflow.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
/*
Sample code for vulnerable type: Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
CWE : CWE-120
Description : The product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow.
*/
#include <stdio.h>
// Source function: Vulnerability - Conversion of integer to char without bounds checking
char convertToInt(int opt) {
return (char)opt; // Source of vulnerability
}
// Sink function: No buffer overflow vulnerability here, just demonstration of using the converted char
void processChar(char opt_char) {
printf("Processed character: %c\n", opt_char);
}
int main() {
int opt = 300; // Assume opt is received from an untrusted source
// Source function call
char opt_char = convertToInt(opt);
// Sink function call
processChar(opt_char);
return 0;
}