Mercurial > hg
annotate contrib/fuzz/bdiff.cc @ 51486:0ddc34330d41
branchcache: do not accept "empty update"
This currently does not happens and it will be simpler that is remains that way.
If all update do something, we will be able to simply declare, in a later
changesets, that all update to result in a dirty branchcache.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 08 Mar 2024 15:06:54 +0100 |
parents | d37658efbec2 |
children |
rev | line source |
---|---|
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 |
43813
5a9e2ae9899b
fuzz: use a more standard approach to allow local builds of fuzzers
Augie Fackler <augie@google.com>
parents:
43809
diff
changeset
|
12 #include "FuzzedDataProvider.h" |
38173
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 |
43809
51a99e09c54b
fuzz: always define LLVMFuzzerInitialize() even if we don't need it
Augie Fackler <augie@google.com>
parents:
43613
diff
changeset
|
17 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) |
51a99e09c54b
fuzz: always define LLVMFuzzerInitialize() even if we don't need it
Augie Fackler <augie@google.com>
parents:
43613
diff
changeset
|
18 { |
51a99e09c54b
fuzz: always define LLVMFuzzerInitialize() even if we don't need it
Augie Fackler <augie@google.com>
parents:
43613
diff
changeset
|
19 return 0; |
51a99e09c54b
fuzz: always define LLVMFuzzerInitialize() even if we don't need it
Augie Fackler <augie@google.com>
parents:
43613
diff
changeset
|
20 } |
51a99e09c54b
fuzz: always define LLVMFuzzerInitialize() even if we don't need it
Augie Fackler <augie@google.com>
parents:
43613
diff
changeset
|
21 |
35670
2b9e2415f5b5
contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
22 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
|
23 { |
43613
dbc39f028c9f
fuzz: migrate bdiff fuzzer to use FuzzedDataProvider
Augie Fackler <augie@google.com>
parents:
38173
diff
changeset
|
24 FuzzedDataProvider provider(Data, Size); |
dbc39f028c9f
fuzz: migrate bdiff fuzzer to use FuzzedDataProvider
Augie Fackler <augie@google.com>
parents:
38173
diff
changeset
|
25 std::string left = provider.ConsumeRandomLengthString(Size); |
dbc39f028c9f
fuzz: migrate bdiff fuzzer to use FuzzedDataProvider
Augie Fackler <augie@google.com>
parents:
38173
diff
changeset
|
26 std::string right = provider.ConsumeRemainingBytesAsString(); |
35670
2b9e2415f5b5
contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
27 |
2b9e2415f5b5
contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
28 struct bdiff_line *a, *b; |
43613
dbc39f028c9f
fuzz: migrate bdiff fuzzer to use FuzzedDataProvider
Augie Fackler <augie@google.com>
parents:
38173
diff
changeset
|
29 int an = bdiff_splitlines(left.c_str(), left.size(), &a); |
dbc39f028c9f
fuzz: migrate bdiff fuzzer to use FuzzedDataProvider
Augie Fackler <augie@google.com>
parents:
38173
diff
changeset
|
30 int bn = bdiff_splitlines(right.c_str(), right.size(), &b); |
35670
2b9e2415f5b5
contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
31 struct bdiff_hunk l; |
2b9e2415f5b5
contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
32 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
|
33 free(a); |
2b9e2415f5b5
contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
34 free(b); |
2b9e2415f5b5
contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
35 bdiff_freehunks(l.next); |
2b9e2415f5b5
contrib: add some basic scaffolding for some fuzz test targets
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
36 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
|
37 } |
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 } // extern "C" |