Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 1 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 2 | // See https://llvm.org/LICENSE.txt for license information. |
| 3 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
George Karpenkov | 10ab2ac | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 4 | |
| 5 | // Simple test for a fuzzer. |
| 6 | // The fuzzer must find a string based on dictionary words: |
| 7 | // "Elvis" |
| 8 | // "Presley" |
| 9 | #include <cstddef> |
| 10 | #include <cstdint> |
| 11 | #include <cstdlib> |
| 12 | #include <cstring> |
| 13 | #include <iostream> |
| 14 | #include <ostream> |
| 15 | |
| 16 | static volatile int Zero = 0; |
| 17 | |
| 18 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { |
| 19 | const char *Expected = "ElvisPresley"; |
| 20 | if (Size < strlen(Expected)) return 0; |
| 21 | size_t Match = 0; |
| 22 | for (size_t i = 0; Expected[i]; i++) |
| 23 | if (Expected[i] + Zero == Data[i]) |
| 24 | Match++; |
| 25 | if (Match == strlen(Expected)) { |
| 26 | std::cout << "BINGO; Found the target, exiting\n" << std::flush; |
| 27 | exit(1); |
| 28 | } |
| 29 | return 0; |
| 30 | } |
| 31 | |