Mercurial > hg
changeset 43613:dbc39f028c9f
fuzz: migrate bdiff fuzzer to use FuzzedDataProvider
Differential Revision: https://phab.mercurial-scm.org/D7368
author | Augie Fackler <augie@google.com> |
---|---|
date | Mon, 11 Nov 2019 14:48:30 -0500 |
parents | dc9c570a3818 |
children | 78df32a8b6f4 |
files | contrib/fuzz/bdiff.cc |
diffstat | 1 files changed, 6 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/fuzz/bdiff.cc Mon Nov 11 16:14:35 2019 -0500 +++ b/contrib/fuzz/bdiff.cc Mon Nov 11 14:48:30 2019 -0500 @@ -9,22 +9,20 @@ #include <memory> #include <stdlib.h> -#include "fuzzutil.h" +#include <fuzzer/FuzzedDataProvider.h> extern "C" { #include "bdiff.h" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { - auto maybe_inputs = SplitInputs(Data, Size); - if (!maybe_inputs) { - return 0; - } - auto inputs = std::move(maybe_inputs.value()); + FuzzedDataProvider provider(Data, Size); + std::string left = provider.ConsumeRandomLengthString(Size); + std::string right = provider.ConsumeRemainingBytesAsString(); struct bdiff_line *a, *b; - int an = bdiff_splitlines(inputs.left.get(), inputs.left_size, &a); - int bn = bdiff_splitlines(inputs.right.get(), inputs.right_size, &b); + int an = bdiff_splitlines(left.c_str(), left.size(), &a); + int bn = bdiff_splitlines(right.c_str(), right.size(), &b); struct bdiff_hunk l; bdiff_diff(a, an, b, bn, &l); free(a);