/src/git/oss-fuzz/fuzz-date.c
Line | Count | Source |
1 | | #include "git-compat-util.h" |
2 | | #include "date.h" |
3 | | |
4 | | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); |
5 | | |
6 | | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
7 | 5.57k | { |
8 | 5.57k | int local; |
9 | 5.57k | int num; |
10 | 5.57k | char *str; |
11 | 5.57k | int16_t tz; |
12 | 5.57k | timestamp_t ts; |
13 | 5.57k | enum date_mode_type dmtype; |
14 | 5.57k | struct date_mode dm; |
15 | | |
16 | 5.57k | if (size <= 4) |
17 | | /* |
18 | | * we use the first byte to fuzz dmtype and the |
19 | | * second byte to fuzz local, then the next two |
20 | | * bytes to fuzz tz offset. The remainder |
21 | | * (at least one byte) is fed as input to |
22 | | * approxidate_careful(). |
23 | | */ |
24 | 4 | return 0; |
25 | | |
26 | 5.57k | local = !!(*data++ & 0x10); |
27 | 5.57k | num = *data++ % DATE_UNIX; |
28 | 5.57k | if (num >= DATE_STRFTIME) |
29 | 539 | num++; |
30 | 5.57k | dmtype = (enum date_mode_type)num; |
31 | 5.57k | size -= 2; |
32 | | |
33 | 5.57k | tz = *data++; |
34 | 5.57k | tz = (tz << 8) | *data++; |
35 | 5.57k | size -= 2; |
36 | | |
37 | 5.57k | str = xmemdupz(data, size); |
38 | | |
39 | 5.57k | ts = approxidate_careful(str, &num); |
40 | 5.57k | free(str); |
41 | | |
42 | 5.57k | dm = date_mode_from_type(dmtype); |
43 | 5.57k | dm.local = local; |
44 | 5.57k | show_date(ts, (int)tz, dm); |
45 | | |
46 | 5.57k | date_mode_release(&dm); |
47 | | |
48 | 5.57k | return 0; |
49 | 5.57k | } |