brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · f4df82e Raw
50 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// Find "FUZZME", the target has 3 different functions.6//7// This test, and the accompanying lit tests8// (dataflow.test, only-some-bytes.test) assume that the compiler9// instruments functions in their lexical order.10// This assumption is not guaranteed, but it is likely to hold.11// It allows to simplify the test quite a bit: in the lit tests12// LLVMFuzzerTestOneInput is "F0", Func1 is "F1", Func2 is "F2".13#include <assert.h>14#include <cstddef>15#include <cstdint>16#include <cstdlib>17#include <cstdio>18 19extern "C" bool Func1(const uint8_t *Data, size_t Size);20extern "C" bool Func2(const uint8_t *Data, size_t Size);21 22extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {23  if (Size >= 524      && Data[0] == 'F'25      && Data[1] == 'U'26      && Data[2] == 'Z'27      && Data[3] == 'Z'28      && Func1(Data, Size)29      && Func2(Data, Size)) {30        fprintf(stderr, "BINGO\n");31        abort();32  }33  return 0;34}35 36extern "C"37__attribute__((noinline))38bool Func1(const uint8_t *Data, size_t Size) {39  // assumes Size >= 5, doesn't check it.40  return Data[4] == 'M';41}42 43extern "C"44__attribute__((noinline))45bool Func2(const uint8_t *Data, size_t Size) {46  return Size >= 6 && Data[5] == 'E';47}48 49 50