forked from git/git
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fuzz: add new oss-fuzz fuzzer for date.c / date.h
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
- Loading branch information
1 parent
dadef80
commit fcc1933
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
fuzz-commit-graph | ||
fuzz-date | ||
fuzz-pack-headers | ||
fuzz-pack-idx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "git-compat-util.h" | ||
#include "date.h" | ||
|
||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); | ||
|
||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) | ||
{ | ||
int local; | ||
int num; | ||
char *str; | ||
int16_t tz; | ||
timestamp_t ts; | ||
enum date_mode_type dmtype; | ||
struct date_mode *dm; | ||
|
||
if (size <= 4) | ||
/* | ||
* we use the first byte to fuzz dmtype and the | ||
* second byte to fuzz local, then the next two | ||
* bytes to fuzz tz offset, and the remainder | ||
* (at least one byte) is fed as input to | ||
* approxidate_careful(). | ||
*/ | ||
return 0; | ||
|
||
local = !!(*data++ & 0x10); | ||
num = *data++ % DATE_UNIX; | ||
if (num >= DATE_STRFTIME) | ||
num++; | ||
dmtype = (enum date_mode_type)num; | ||
size -= 2; | ||
|
||
tz = *data++; | ||
tz = (tz << 8) | *data++; | ||
size -= 2; | ||
|
||
str = xmemdupz(data, size); | ||
|
||
ts = approxidate_careful(str, &num); | ||
free(str); | ||
|
||
dm = date_mode_from_type(dmtype); | ||
dm->local = local; | ||
show_date(ts, (int)tz, dm); | ||
|
||
date_mode_release(dm); | ||
|
||
return 0; | ||
} |