-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
56 lines (45 loc) · 1.13 KB
/
test.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
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
// +------------------------------------------+
// | header | length | chunk1 | chunk2 | data |
// +------------------------------------------+
// 2bytes 4bytes 2bytes 4bytes nbytes
int vuln(char* str, int len) {
int offset = 0;
if (len <= 12) {
printf("data format error\n");
return 0;
}
char* header = str + offset;
offset = offset + 2;
int length = atoi(str);
offset = offset + 4;
char* chunk1 = str + offset;
offset = offset + 2;
char* chunk2 = str + offset;
offset = offset + 4;
char* data = str + offset;
if (length > 0xF0000000) {
printf("length = %x\n", length);
raise(SIGSEGV);
}
else if (data[0] == 'A') {
printf("data[0] %c\n", data[0]);
raise(SIGSEGV);
}
else {
printf("OK\n");
}
return 0;
}
int main(int argc, char *argv[]) {
char buf[1024]={0};
FILE* fp = fopen(argv[1], "rb");
int n = fread(buf, 1, 1024, fp);
//printf("%d %s\n", n, buf);
vuln(buf, n);
return 0;
}