The seventh batch
[git.git] / oss-fuzz / fuzz-date.c
blob9619dae40ed89935a7333b976ae3e540f95d3ffb
1 #include "git-compat-util.h"
2 #include "date.h"
4 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
6 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
8 int local;
9 int num;
10 char *str;
11 int16_t tz;
12 timestamp_t ts;
13 enum date_mode_type dmtype;
14 struct date_mode dm;
16 if (size <= 4)
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().
24 return 0;
26 local = !!(*data++ & 0x10);
27 num = *data++ % DATE_UNIX;
28 if (num >= DATE_STRFTIME)
29 num++;
30 dmtype = (enum date_mode_type)num;
31 size -= 2;
33 tz = *data++;
34 tz = (tz << 8) | *data++;
35 size -= 2;
37 str = xmemdupz(data, size);
39 ts = approxidate_careful(str, &num);
40 free(str);
42 dm = date_mode_from_type(dmtype);
43 dm.local = local;
44 show_date(ts, (int)tz, dm);
46 date_mode_release(&dm);
48 return 0;