git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] fuzz: add new oss-fuzz fuzzer for date.c / date.h

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 13, 2023, 23:27 UTC
Message-ID
<xmqq4jhp5j4q.fsf@gitster.g>
In-Reply-To
<pull.1612.v2.git.1699892568344.gitgitgadget@gmail.com>
"Arthur Chan via GitGitGadget" <gitgitgadget@gmail.com> writes:
> +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);

It is somewhat annoying that everybody has to repeat this twice here, but it is not your fault X-<.

Show 5 quoted lines
> +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
> +{
> +	int local;
> +	int num;
> +	uint16_t tz;

tz offset can be negative, so uint16_t is not appropriate. See date.c:gm_time_t() that is eventually called from show_date().

Show 21 quoted lines
> +	char *str;
> +	timestamp_t ts;
> +	enum date_mode_type dmtype;
> +	struct date_mode *dm;
> +
> +	if (size <= 4)
> +		/*
> +		 * we use the first byte to fuzz dmtype and local,
> +		 * then the next three bytes to fuzz tz	offset,
> +		 * and the remainder (at least one byte) is fed
> +		 * as end-user input to approxidate_careful().
> +		 */
> +		return 0;
> +
> +	local = !!(*data & 0x10);
> +	dmtype = (enum date_mode_type)(*data % DATE_UNIX);
> +	if (dmtype == DATE_STRFTIME)
> +		/*
> +		 * Currently DATE_STRFTIME is not supported.
> +		 */
> +		return 0;

There is an off-by-one error above, as modulo DATE_UNIX will never yield DATE_UNIX. Presumably we could do something silly like

	tmp = *data % DATE_UNIX;
	if (DATE_STRFTIME <= tmp)
		tmp++;
	dmtime = (enum date_mode_type)tmp;

to pick values from [0..DATE_UNIX) and then shift everything above DATE_STRFTIME by one to create a hole there and fill DATE_UNIX at the same time, without wasting a sample by returning.

Show 7 quoted lines
> +	data++;
> +	size--;
> +
> +	tz = *data++;
> +	tz = (tz << 8) | *data++;
> +	tz = (tz << 8) | *data++;
> +	size -= 3;

If your tz is 16-bit wide, then we do not have to eat three bytes here, do we?

You never answered my question on your intention. Is "tz" considered attacker controlled (and needs to be fuzzed including invalid values)?

Show 19 quoted lines
> +	str = (char *)malloc(size + 1);
> +	if (!str)
> +		return 0;
> +	memcpy(str, data, size);
> +	str[size] = '\0';
> +
> +	ts = approxidate_careful(str, &num);
> +	free(str);
> +
> +	dm = date_mode_from_type(dmtype);
> +	dm->local = local;
> +	show_date(ts, (int16_t)tz, dm);
> +
> +	date_mode_release(dm);
> +
> +	return 0;
> +}
>
> base-commit: dadef801b365989099a9929e995589e455c51fed
Thanks.
Previous: Junio C HamanoNext: Arthur Chan via GitGitGadget
Message 7 of 10 in “fuzz: add new oss-fuzz fuzzer for date.c / date.h”
  1. fuzz: add new oss-fuzz fuzzer for date.c / date.hArthur Chan via GitGitGadget, Nov 11, 2023
  2. Junio C HamanoNov 12, 2023
  3. Junio C HamanoNov 12, 2023
  4. fuzz: add new oss-fuzz fuzzer for date.c / date.hArthur Chan via GitGitGadget, Nov 13, 2023
  5. Jeff KingNov 13, 2023
  6. Junio C HamanoNov 13, 2023
  7. Junio C HamanoNov 13, 2023
  8. fuzz: add new oss-fuzz fuzzer for date.c / date.hArthur Chan via GitGitGadget, Nov 14, 2023
  9. Junio C HamanoNov 14, 2023
  10. fuzz: add new oss-fuzz fuzzer for date.c / date.hArthur Chan via GitGitGadget, Nov 17, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.