Debian Codegraph @

tests/thirdparty/Fuzzer/test/SwapCmpTest.cpp

raw
1 // This file is distributed under the University of Illinois Open Source
2 // License. See LICENSE.TXT for details.
3
4 // The fuzzer must find several constants with swapped bytes.
5 #include <cstdint>
6 #include <cstdlib>
7 #include <cstring>
8 #include <cstdio>
9
10 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
11 if (Size < 14) return 0;
12 uint64_t x = 0;
13 uint32_t y = 0;
14 uint16_t z = 0;
15 memcpy(&x, Data, sizeof(x));
16 memcpy(&y, Data + Size / 2, sizeof(y));
17 memcpy(&z, Data + Size - sizeof(z), sizeof(z));
18
19 x = __builtin_bswap64(x);
20 y = __builtin_bswap32(y);
21 z = __builtin_bswap16(z);
22
23 if (x == 0x46555A5A5A5A5546ULL &&
24 z == 0x4F4B &&
25 y == 0x66757A7A &&
26 true
27 ) {
28 if (Data[Size - 3] == 'z') {
29 fprintf(stderr, "BINGO; Found the target\n");
30 exit(1);
31 }
32 }
33 return 0;
34 }