1c5f01b2fSopenharmony_ci// This file is distributed under the University of Illinois Open Source
2c5f01b2fSopenharmony_ci// License. See LICENSE.TXT for details.
3c5f01b2fSopenharmony_ci
4c5f01b2fSopenharmony_ci// Simple test for a cutom mutator.
5c5f01b2fSopenharmony_ci#include <assert.h>
6c5f01b2fSopenharmony_ci#include <cstdint>
7c5f01b2fSopenharmony_ci#include <cstdlib>
8c5f01b2fSopenharmony_ci#include <cstddef>
9c5f01b2fSopenharmony_ci#include <iostream>
10c5f01b2fSopenharmony_ci
11c5f01b2fSopenharmony_ci#include "FuzzerInterface.h"
12c5f01b2fSopenharmony_ci
13c5f01b2fSopenharmony_cistatic volatile int Sink;
14c5f01b2fSopenharmony_ci
15c5f01b2fSopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
16c5f01b2fSopenharmony_ci  assert(Data);
17c5f01b2fSopenharmony_ci  if (Size > 0 && Data[0] == 'H') {
18c5f01b2fSopenharmony_ci    Sink = 1;
19c5f01b2fSopenharmony_ci    if (Size > 1 && Data[1] == 'i') {
20c5f01b2fSopenharmony_ci      Sink = 2;
21c5f01b2fSopenharmony_ci      if (Size > 2 && Data[2] == '!') {
22c5f01b2fSopenharmony_ci        std::cout << "BINGO; Found the target, exiting\n";
23c5f01b2fSopenharmony_ci        exit(1);
24c5f01b2fSopenharmony_ci      }
25c5f01b2fSopenharmony_ci    }
26c5f01b2fSopenharmony_ci  }
27c5f01b2fSopenharmony_ci  return 0;
28c5f01b2fSopenharmony_ci}
29c5f01b2fSopenharmony_ci
30c5f01b2fSopenharmony_ciextern "C" size_t LLVMFuzzerCustomMutator(uint8_t *Data, size_t Size,
31c5f01b2fSopenharmony_ci                                          size_t MaxSize, unsigned int Seed) {
32c5f01b2fSopenharmony_ci  static bool Printed;
33c5f01b2fSopenharmony_ci  if (!Printed) {
34c5f01b2fSopenharmony_ci    std::cerr << "In LLVMFuzzerCustomMutator\n";
35c5f01b2fSopenharmony_ci    Printed = true;
36c5f01b2fSopenharmony_ci  }
37c5f01b2fSopenharmony_ci  return LLVMFuzzerMutate(Data, Size, MaxSize);
38c5f01b2fSopenharmony_ci}
39