contrib/fuzz/bdiff.cc
author Gregory Szorc <gregory.szorc@gmail.com>
Sat, 03 Aug 2019 16:47:49 -0700
changeset 42697 3e3fb15bfeea
parent 38173 fa0ddd5e8fff
child 43613 dbc39f028c9f
permissions -rw-r--r--
automation: increase root volume size on Linux It is close to full in the AMI. I actually ran out of space running tests without increasing the volume size! Differential Revision: https://phab.mercurial-scm.org/D6716
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35670
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
     1
/*
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
     2
 * bdiff.cc - fuzzer harness for bdiff.c
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
     3
 *
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
     4
 * Copyright 2018, Google Inc.
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
     5
 *
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
     6
 * This software may be used and distributed according to the terms of
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
     7
 * the GNU General Public License, incorporated herein by reference.
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
     8
 */
38173
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents: 35670
diff changeset
     9
#include <memory>
35670
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    10
#include <stdlib.h>
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    11
38173
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents: 35670
diff changeset
    12
#include "fuzzutil.h"
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents: 35670
diff changeset
    13
35670
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    14
extern "C" {
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    15
#include "bdiff.h"
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    16
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    17
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    18
{
38173
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents: 35670
diff changeset
    19
	auto maybe_inputs = SplitInputs(Data, Size);
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents: 35670
diff changeset
    20
	if (!maybe_inputs) {
35670
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    21
		return 0;
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    22
	}
38173
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents: 35670
diff changeset
    23
	auto inputs = std::move(maybe_inputs.value());
35670
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    24
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    25
	struct bdiff_line *a, *b;
38173
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents: 35670
diff changeset
    26
	int an = bdiff_splitlines(inputs.left.get(), inputs.left_size, &a);
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents: 35670
diff changeset
    27
	int bn = bdiff_splitlines(inputs.right.get(), inputs.right_size, &b);
35670
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    28
	struct bdiff_hunk l;
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    29
	bdiff_diff(a, an, b, bn, &l);
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    30
	free(a);
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    31
	free(b);
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    32
	bdiff_freehunks(l.next);
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    33
	return 0; // Non-zero return values are reserved for future use.
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    34
}
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    35
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    36
#ifdef HG_FUZZER_INCLUDE_MAIN
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    37
int main(int argc, char **argv)
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    38
{
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    39
	const char data[] = "asdf";
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    40
	return LLVMFuzzerTestOneInput((const uint8_t *)data, 4);
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    41
}
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    42
#endif
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    43
2b9e2415f5b5 contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff changeset
    44
} // extern "C"