-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvuln.c
44 lines (38 loc) · 972 Bytes
/
vuln.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
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <string.h>
#define MIN_BUF_SIZE 60
void vuln(unsigned char *src, size_t size_)
{
unsigned char buf1[MIN_BUF_SIZE];
int size = size_;
if(size < MIN_BUF_SIZE) {
memcpy(buf1, src, size);
memset(buf1 + size, 0, MIN_BUF_SIZE - size);
}
}
void not_vuln(unsigned char *src, size_t size_)
{
unsigned char buf1[MIN_BUF_SIZE];
size_t size = size_;
if(size < MIN_BUF_SIZE) {
memcpy(buf1, src, size);
memset(buf1 + size, 0, MIN_BUF_SIZE - size);
}
}
int main(int argc, char **argv)
{
if(argc < 2) {
return 0;
}
if(!strcmp(argv[1], "vuln")) {
char buf[128] = { 0 };
memset(buf, 0x41, sizeof(buf)-1);
vuln((unsigned char *)&buf, -1);
}
else if(!strcmp(argv[1], "notvuln")) {
char buf[MIN_BUF_SIZE] = { 0 };
memset(buf, 0x42, sizeof(buf)-1);
not_vuln((unsigned char *)&buf, MIN_BUF_SIZE-1);
}
return 0;
}