File: fuzz-date.c

package info (click to toggle)
git 1%3A2.50.1-0.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 61,696 kB
  • sloc: ansic: 302,907; sh: 260,696; perl: 27,874; tcl: 22,303; makefile: 4,280; python: 3,442; javascript: 772; csh: 45; lisp: 12
file content (49 lines) | stat: -rw-r--r-- 947 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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;
}