blob: d4c2cd23927c882b6619c662cc39d280e2169671 [file] [log] [blame]
Chandler Carruth2946cd72019-01-19 08:50:56 +00001// 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 Karpenkov10ab2ac2017-08-21 23:25:50 +00004
5// The fuzzer must find several constants with swapped bytes.
6#include <cstdint>
7#include <cstdio>
8#include <cstdlib>
9#include <cstring>
10
11extern "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 Morehouse5317f2e2018-03-23 23:35:28 +000015 uint32_t z = 0;
George Karpenkov10ab2ac2017-08-21 23:25:50 +000016 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 Morehouse5317f2e2018-03-23 23:35:28 +000022 z = __builtin_bswap32(z);
George Karpenkov10ab2ac2017-08-21 23:25:50 +000023 const bool k32bit = sizeof(void*) == 4;
24
25 if ((k32bit || x == 0x46555A5A5A5A5546ULL) &&
26 z == 0x4F4B &&
27 y == 0x66757A7A &&
28 true
29 ) {
Matt Morehouse5317f2e2018-03-23 23:35:28 +000030 if (Data[Size - 5] == 'z') {
George Karpenkov10ab2ac2017-08-21 23:25:50 +000031 fprintf(stderr, "BINGO; Found the target\n");
32 exit(1);
33 }
34 }
35 return 0;
36}