Skip to content

Commit 3335365

Browse files
committed
Merge branch 'ac/fuzz-show-date'
Subject approxidate() and show_date() machinery to OSS-Fuzz. * ac/fuzz-show-date: fuzz: add new oss-fuzz fuzzer for date.c / date.h
2 parents 71c7466 + ee41e2d commit 3335365

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ SCRIPTS = $(SCRIPT_SH_GEN) \
753753
ETAGS_TARGET = TAGS
754754

755755
FUZZ_OBJS += oss-fuzz/fuzz-commit-graph.o
756+
FUZZ_OBJS += oss-fuzz/fuzz-date.o
756757
FUZZ_OBJS += oss-fuzz/fuzz-pack-headers.o
757758
FUZZ_OBJS += oss-fuzz/fuzz-pack-idx.o
758759
.PHONY: fuzz-objs

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
2+
fuzz-date
23
fuzz-pack-headers
34
fuzz-pack-idx

oss-fuzz/fuzz-date.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 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;
15+
16+
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+
return 0;
25+
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;
32+
33+
tz = *data++;
34+
tz = (tz << 8) | *data++;
35+
size -= 2;
36+
37+
str = xmemdupz(data, size);
38+
39+
ts = approxidate_careful(str, &num);
40+
free(str);
41+
42+
dm = date_mode_from_type(dmtype);
43+
dm->local = local;
44+
show_date(ts, (int)tz, dm);
45+
46+
date_mode_release(dm);
47+
48+
return 0;
49+
}

0 commit comments

Comments
 (0)