Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Chan <arthur.chan@adalogics.com>2023-11-17 20:47:47 +0300
committerJunio C Hamano <gitster@pobox.com>2023-11-20 02:17:51 +0300
commitee41e2d41ffe05b0521e1b6d929b59db310d326e (patch)
treee1bfde6271e524422fd3e544c7bb5d1c42c198cb /oss-fuzz
parent61a22ddaf0626111193a17ac12f366bd6d167dff (diff)
fuzz: add new oss-fuzz fuzzer for date.c / date.h
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'oss-fuzz')
-rw-r--r--oss-fuzz/.gitignore1
-rw-r--r--oss-fuzz/fuzz-date.c49
2 files changed, 50 insertions, 0 deletions
diff --git a/oss-fuzz/.gitignore b/oss-fuzz/.gitignore
index 9acb74412e..5b95408825 100644
--- a/oss-fuzz/.gitignore
+++ b/oss-fuzz/.gitignore
@@ -1,3 +1,4 @@
fuzz-commit-graph
+fuzz-date
fuzz-pack-headers
fuzz-pack-idx
diff --git a/oss-fuzz/fuzz-date.c b/oss-fuzz/fuzz-date.c
new file mode 100644
index 0000000000..036378b946
--- /dev/null
+++ b/oss-fuzz/fuzz-date.c
@@ -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. 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;
+}