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 | // The fuzzer must find several constants with swapped bytes. |
| 6 | #include <cstdint> |
| 7 | #include <cstdio> |
| 8 | #include <cstdlib> |
| 9 | #include <cstring> |
| 10 | |
| 11 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { |
| 12 | if (Size < 14) return 0; |
| 13 | uint64_t x = 0; |
| 14 | uint32_t y = 0; |
Matt Morehouse | 5317f2e | 2018-03-23 23:35:28 +0000 | [diff] [blame] | 15 | uint32_t z = 0; |
George Karpenkov | 10ab2ac | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 16 | memcpy(&x, Data, sizeof(x)); |
| 17 | memcpy(&y, Data + Size / 2, sizeof(y)); |
| 18 | memcpy(&z, Data + Size - sizeof(z), sizeof(z)); |
| 19 | |
| 20 | x = __builtin_bswap64(x); |
| 21 | y = __builtin_bswap32(y); |
Matt Morehouse | 5317f2e | 2018-03-23 23:35:28 +0000 | [diff] [blame] | 22 | z = __builtin_bswap32(z); |
George Karpenkov | 10ab2ac | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 23 | const bool k32bit = sizeof(void*) == 4; |
| 24 | |
| 25 | if ((k32bit || x == 0x46555A5A5A5A5546ULL) && |
| 26 | z == 0x4F4B && |
| 27 | y == 0x66757A7A && |
| 28 | true |
| 29 | ) { |
Matt Morehouse | 5317f2e | 2018-03-23 23:35:28 +0000 | [diff] [blame] | 30 | if (Data[Size - 5] == 'z') { |
George Karpenkov | 10ab2ac | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 31 | fprintf(stderr, "BINGO; Found the target\n"); |
| 32 | exit(1); |
| 33 | } |
| 34 | } |
| 35 | return 0; |
| 36 | } |