Skip to content

Commit d43724c

Browse files
committed
fuzz: add new oss-fuzz fuzzer for date.c / date.h
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
1 parent dadef80 commit d43724c

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,7 @@ ETAGS_TARGET = TAGS
752752
FUZZ_OBJS += oss-fuzz/fuzz-commit-graph.o
753753
FUZZ_OBJS += oss-fuzz/fuzz-pack-headers.o
754754
FUZZ_OBJS += oss-fuzz/fuzz-pack-idx.o
755+
FUZZ_OBJS += oss-fuzz/fuzz-date.o
755756
.PHONY: fuzz-objs
756757
fuzz-objs: $(FUZZ_OBJS)
757758

oss-fuzz/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
fuzz-commit-graph
22
fuzz-pack-headers
33
fuzz-pack-idx
4+
fuzz-date

oss-fuzz/fuzz-date.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
{
8+
int type;
9+
int time;
10+
int num;
11+
char *str;
12+
timestamp_t ts;
13+
enum date_mode_type dmtype;
14+
struct date_mode *dm;
15+
16+
if (size <= 8)
17+
{
18+
return 0;
19+
}
20+
21+
type = (*((int *)data)) % 8;
22+
data += 4;
23+
size -= 4;
24+
25+
time = abs(*((int *)data));
26+
data += 4;
27+
size -= 4;
28+
29+
str = (char *)malloc(size+1);
30+
if (!str)
31+
{
32+
return 0;
33+
}
34+
memcpy(str, data, size);
35+
str[size] = '\0';
36+
37+
ts = approxidate_careful(str, &num);
38+
free(str);
39+
40+
switch(type)
41+
{
42+
case 0: default:
43+
dmtype = DATE_NORMAL;
44+
break;
45+
case 1:
46+
dmtype = DATE_HUMAN;
47+
break;
48+
case 2:
49+
dmtype = DATE_SHORT;
50+
break;
51+
case 3:
52+
dmtype = DATE_ISO8601;
53+
break;
54+
case 4:
55+
dmtype = DATE_ISO8601_STRICT;
56+
break;
57+
case 5:
58+
dmtype = DATE_RFC2822;
59+
break;
60+
case 6:
61+
dmtype = DATE_RAW;
62+
break;
63+
case 7:
64+
dmtype = DATE_UNIX;
65+
break;
66+
}
67+
68+
dm = date_mode_from_type(dmtype);
69+
dm->local = 1;
70+
show_date(ts, time, dm);
71+
72+
date_mode_release(dm);
73+
74+
return 0;
75+
}

0 commit comments

Comments
 (0)