blob: 12cafae6635e6e59edcc497b7d348b3167df6fba [file] [log] [blame]
Chandler Carruth2946cd72019-01-19 08:50:56 +00001// 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-exception
George Karpenkov10ab2ac2017-08-21 23:25:50 +00004
5// Break through a series of strcmp.
6#include <cassert>
7#include <cstdint>
8#include <cstdio>
9#include <cstdlib>
10#include <cstring>
11
12bool Eq(const uint8_t *Data, size_t Size, const char *Str) {
13 char Buff[1024];
14 size_t Len = strlen(Str);
15 if (Size < Len) return false;
16 if (Len >= sizeof(Buff)) return false;
17 memcpy(Buff, (const char*)Data, Len);
18 Buff[Len] = 0;
19 int res = strcmp(Buff, Str);
20 return res == 0;
21}
22
23extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
24 if (Eq(Data, Size, "ABC") &&
25 Size >= 3 && Eq(Data + 3, Size - 3, "QWER") &&
26 Size >= 7 && Eq(Data + 7, Size - 7, "ZXCVN") &&
27 Size >= 14 && Data[13] == 42
28 ) {
29 fprintf(stderr, "BINGO\n");
30 exit(1);
31 }
32 return 0;
33}