Skip to content

Commit 4cc78fa

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 337a8b0 commit 4cc78fa

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

Makefile

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

752752
FUZZ_OBJS += oss-fuzz/fuzz-commit-graph.o
753+
FUZZ_OBJS += oss-fuzz/fuzz-date.o
753754
FUZZ_OBJS += oss-fuzz/fuzz-pack-headers.o
754755
FUZZ_OBJS += oss-fuzz/fuzz-pack-idx.o
755756
.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: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
int tz;
11+
char *str;
12+
int8_t *tmp_data;
13+
timestamp_t ts;
14+
enum date_mode_type dmtype;
15+
struct date_mode *dm;
16+
17+
if (size <= 4)
18+
/*
19+
* we use the first byte to fuzz dmtype and local,
20+
* then the next three bytes to fuzz tz offset,
21+
* and the remainder (at least one byte) is fed
22+
* as end-user input to 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+
data++;
32+
size--;
33+
34+
tmp_data = (int8_t*)data;
35+
tz = *tmp_data++;
36+
tz = (tz << 8) | *tmp_data++;
37+
tz = (tz << 8) | *tmp_data++;
38+
data += 3;
39+
size -= 3;
40+
41+
str = xmemdupz(data, size);
42+
43+
ts = approxidate_careful(str, &num);
44+
free(str);
45+
46+
dm = date_mode_from_type(dmtype);
47+
dm->local = local;
48+
show_date(ts, tz, dm);
49+
50+
date_mode_release(dm);
51+
52+
return 0;
53+
}

0 commit comments

Comments
 (0)