Skip to content

Commit

Permalink
fuzz: add new oss-fuzz fuzzer for date.c / date.h
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
  • Loading branch information
arthurscchan committed Nov 10, 2023
1 parent dadef80 commit c9f0314
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ ETAGS_TARGET = TAGS
FUZZ_OBJS += oss-fuzz/fuzz-commit-graph.o
FUZZ_OBJS += oss-fuzz/fuzz-pack-headers.o
FUZZ_OBJS += oss-fuzz/fuzz-pack-idx.o
FUZZ_OBJS += oss-fuzz/fuzz-date.o
.PHONY: fuzz-objs
fuzz-objs: $(FUZZ_OBJS)

Expand Down
1 change: 1 addition & 0 deletions oss-fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
fuzz-commit-graph
fuzz-pack-headers
fuzz-pack-idx
fuzz-date
69 changes: 69 additions & 0 deletions oss-fuzz/fuzz-date.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#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)
{
if (size <= 8)
{
return 0;
}

int type = (*((int *)data)) % 8;

Check failure on line 13 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-musl (alpine)

oss-fuzz/fuzz-date.c:13:9: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 13 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-TEST-vars (ubuntu-20.04)

oss-fuzz/fuzz-date.c:13:2: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 13 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-sha256 (ubuntu-latest)

oss-fuzz/fuzz-date.c:13:6: mixing declarations and code is incompatible with standards before C99 [-Werror,-Wdeclaration-after-statement]

Check failure on line 13 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-asan-ubsan (ubuntu-latest)

oss-fuzz/fuzz-date.c:13:6: mixing declarations and code is incompatible with standards before C99 [-Werror,-Wdeclaration-after-statement]

Check failure on line 13 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-gcc-default (ubuntu-latest)

oss-fuzz/fuzz-date.c:13:9: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 13 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-leaks (ubuntu-latest)

oss-fuzz/fuzz-date.c:13:9: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 13 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-gcc (ubuntu-20.04)

oss-fuzz/fuzz-date.c:13:2: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 13 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / pedantic (fedora)

oss-fuzz/fuzz-date.c:13:9: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 13 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux32 (daald/ubuntu32:xenial)

oss-fuzz/fuzz-date.c:13:2: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
data += 4;
size -= 4;

int time = abs(*((int *)data));

Check failure on line 17 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-musl (alpine)

oss-fuzz/fuzz-date.c:17:9: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 17 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-TEST-vars (ubuntu-20.04)

oss-fuzz/fuzz-date.c:17:2: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 17 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-gcc-default (ubuntu-latest)

oss-fuzz/fuzz-date.c:17:9: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 17 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-leaks (ubuntu-latest)

oss-fuzz/fuzz-date.c:17:9: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 17 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-gcc (ubuntu-20.04)

oss-fuzz/fuzz-date.c:17:2: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 17 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / pedantic (fedora)

oss-fuzz/fuzz-date.c:17:9: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 17 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux32 (daald/ubuntu32:xenial)

oss-fuzz/fuzz-date.c:17:2: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
data += 4;
size -= 4;

char *str = (char *)malloc(size+1);

Check failure on line 21 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-musl (alpine)

oss-fuzz/fuzz-date.c:21:9: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 21 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-TEST-vars (ubuntu-20.04)

oss-fuzz/fuzz-date.c:21:2: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 21 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-gcc-default (ubuntu-latest)

oss-fuzz/fuzz-date.c:21:9: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 21 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-leaks (ubuntu-latest)

oss-fuzz/fuzz-date.c:21:9: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 21 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-gcc (ubuntu-20.04)

oss-fuzz/fuzz-date.c:21:2: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 21 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / pedantic (fedora)

oss-fuzz/fuzz-date.c:21:9: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 21 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux32 (daald/ubuntu32:xenial)

oss-fuzz/fuzz-date.c:21:2: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
if (str == NULL)
{
return 0;
}
memcpy(str, data, size);
str[size] = '\0';

int errno;

Check failure on line 29 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-musl (alpine)

oss-fuzz/fuzz-date.c:29:9: function declaration isn't a prototype [-Werror=strict-prototypes]

Check failure on line 29 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-musl (alpine)

oss-fuzz/fuzz-date.c:29:9: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 29 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-TEST-vars (ubuntu-20.04)

oss-fuzz/fuzz-date.c:29:2: function declaration isn’t a prototype [-Werror=strict-prototypes]

Check failure on line 29 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-TEST-vars (ubuntu-20.04)

oss-fuzz/fuzz-date.c:29:2: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 29 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-sha256 (ubuntu-latest)

oss-fuzz/fuzz-date.c:29:6: this function declaration is not a prototype [-Werror,-Wstrict-prototypes]

Check failure on line 29 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-asan-ubsan (ubuntu-latest)

oss-fuzz/fuzz-date.c:29:6: this function declaration is not a prototype [-Werror,-Wstrict-prototypes]

Check failure on line 29 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-gcc-default (ubuntu-latest)

oss-fuzz/fuzz-date.c:29:9: function declaration isn’t a prototype [-Werror=strict-prototypes]

Check failure on line 29 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-gcc-default (ubuntu-latest)

oss-fuzz/fuzz-date.c:29:9: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 29 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-leaks (ubuntu-latest)

oss-fuzz/fuzz-date.c:29:9: function declaration isn’t a prototype [-Werror=strict-prototypes]

Check failure on line 29 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-leaks (ubuntu-latest)

oss-fuzz/fuzz-date.c:29:9: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 29 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-gcc (ubuntu-20.04)

oss-fuzz/fuzz-date.c:29:2: function declaration isn’t a prototype [-Werror=strict-prototypes]

Check failure on line 29 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-gcc (ubuntu-20.04)

oss-fuzz/fuzz-date.c:29:2: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 29 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / pedantic (fedora)

oss-fuzz/fuzz-date.c:29:9: function declaration isn't a prototype [-Werror=strict-prototypes]

Check failure on line 29 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / pedantic (fedora)

oss-fuzz/fuzz-date.c:29:9: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 29 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux32 (daald/ubuntu32:xenial)

oss-fuzz/fuzz-date.c:29:2: function declaration isn't a prototype [-Werror=strict-prototypes]

Check failure on line 29 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux32 (daald/ubuntu32:xenial)

oss-fuzz/fuzz-date.c:29:2: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
timestamp_t ts = approxidate_careful(str, &errno);
free(str);

enum date_mode_type dmtype;

Check failure on line 33 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-musl (alpine)

oss-fuzz/fuzz-date.c:33:9: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 33 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-TEST-vars (ubuntu-20.04)

oss-fuzz/fuzz-date.c:33:2: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 33 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-gcc-default (ubuntu-latest)

oss-fuzz/fuzz-date.c:33:9: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 33 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-leaks (ubuntu-latest)

oss-fuzz/fuzz-date.c:33:9: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 33 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-gcc (ubuntu-20.04)

oss-fuzz/fuzz-date.c:33:2: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 33 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / pedantic (fedora)

oss-fuzz/fuzz-date.c:33:9: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 33 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux32 (daald/ubuntu32:xenial)

oss-fuzz/fuzz-date.c:33:2: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
switch(type)
{
case 0: default:
dmtype = DATE_NORMAL;
break;
case 1:
dmtype = DATE_HUMAN;
break;
case 2:
dmtype = DATE_SHORT;
break;
case 3:
dmtype = DATE_ISO8601;
break;
case 4:
dmtype = DATE_ISO8601_STRICT;
break;
case 5:
dmtype = DATE_RFC2822;
break;
case 6:
dmtype = DATE_RAW;
break;
case 7:
dmtype = DATE_UNIX;
break;
}

struct date_mode *dm = date_mode_from_type(dmtype);

Check failure on line 62 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-musl (alpine)

oss-fuzz/fuzz-date.c:62:9: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 62 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-TEST-vars (ubuntu-20.04)

oss-fuzz/fuzz-date.c:62:2: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 62 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-gcc-default (ubuntu-latest)

oss-fuzz/fuzz-date.c:62:9: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 62 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-leaks (ubuntu-latest)

oss-fuzz/fuzz-date.c:62:9: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 62 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux-gcc (ubuntu-20.04)

oss-fuzz/fuzz-date.c:62:2: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 62 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / pedantic (fedora)

oss-fuzz/fuzz-date.c:62:9: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

Check failure on line 62 in oss-fuzz/fuzz-date.c

View workflow job for this annotation

GitHub Actions / linux32 (daald/ubuntu32:xenial)

oss-fuzz/fuzz-date.c:62:2: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
dm->local = 1;
show_date(ts, time, dm);

date_mode_release(dm);

return 0;
}

0 comments on commit c9f0314

Please sign in to comment.