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 fuzzer. The fuzzer must find a particular string.
5c5f01b2fSopenharmony_ci#include <cstring>
6c5f01b2fSopenharmony_ci#include <cstdint>
7c5f01b2fSopenharmony_ci#include <cstdio>
8c5f01b2fSopenharmony_ci#include <cstdlib>
9c5f01b2fSopenharmony_ci
10c5f01b2fSopenharmony_cistatic volatile int sink;
11c5f01b2fSopenharmony_ci
12c5f01b2fSopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
13c5f01b2fSopenharmony_ci  // TODO: check other sizes.
14c5f01b2fSopenharmony_ci  char *S = (char*)Data;
15c5f01b2fSopenharmony_ci  if (Size >= 8 && strncmp(S, "123", 8))
16c5f01b2fSopenharmony_ci    sink = 1;
17c5f01b2fSopenharmony_ci  if (Size >= 8 && strncmp(S, "01234567", 8) == 0) {
18c5f01b2fSopenharmony_ci    if (Size >= 12 && strncmp(S + 8, "ABCD", 4) == 0) {
19c5f01b2fSopenharmony_ci      if (Size >= 14 && strncmp(S + 12, "XY", 2) == 0) {
20c5f01b2fSopenharmony_ci        if (Size >= 17 && strncmp(S + 14, "KLM", 3) == 0) {
21c5f01b2fSopenharmony_ci          fprintf(stderr, "BINGO\n");
22c5f01b2fSopenharmony_ci          exit(1);
23c5f01b2fSopenharmony_ci        }
24c5f01b2fSopenharmony_ci      }
25c5f01b2fSopenharmony_ci    }
26c5f01b2fSopenharmony_ci  }
27c5f01b2fSopenharmony_ci  return 0;
28c5f01b2fSopenharmony_ci}
29