42 lines · cpp
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-exception4 5// Simple test for a fuzzer.6// Needs to find a string "FUZZxxxxxxxxxxxxMxxE", where 'x' is any byte.7#include <assert.h>8#include <cstddef>9#include <cstdint>10#include <cstdlib>11#include <cstdio>12 13extern "C" bool Func1(const uint8_t *Data, size_t Size);14extern "C" bool Func2(const uint8_t *Data, size_t Size);15 16extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {17 if (Size >= 2018 && Data[0] == 'F'19 && Data[1] == 'U'20 && Data[2] == 'Z'21 && Data[3] == 'Z'22 && Func1(Data, Size)23 && Func2(Data, Size)) {24 fprintf(stderr, "BINGO\n");25 abort();26 }27 return 0;28}29 30extern "C"31__attribute__((noinline))32bool Func1(const uint8_t *Data, size_t Size) {33 // assumes Size >= 5, doesn't check it.34 return Data[16] == 'M';35}36 37extern "C"38__attribute__((noinline))39bool Func2(const uint8_t *Data, size_t Size) {40 return Size >= 20 && Data[19] == 'E';41}42