]> git.proxmox.com Git - rustc.git/blob - src/libcompiler_builtins/compiler-rt/test/fuzzer/StrcmpTest.cpp
New upstream version 1.25.0+dfsg1
[rustc.git] / src / libcompiler_builtins / compiler-rt / test / fuzzer / StrcmpTest.cpp
1 // This file is distributed under the University of Illinois Open Source
2 // License. See LICENSE.TXT for details.
3
4 // Break through a series of strcmp.
5 #include <cassert>
6 #include <cstdint>
7 #include <cstdio>
8 #include <cstdlib>
9 #include <cstring>
10
11 bool Eq(const uint8_t *Data, size_t Size, const char *Str) {
12 char Buff[1024];
13 size_t Len = strlen(Str);
14 if (Size < Len) return false;
15 if (Len >= sizeof(Buff)) return false;
16 memcpy(Buff, (const char*)Data, Len);
17 Buff[Len] = 0;
18 int res = strcmp(Buff, Str);
19 return res == 0;
20 }
21
22 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
23 if (Eq(Data, Size, "ABC") &&
24 Size >= 3 && Eq(Data + 3, Size - 3, "QWER") &&
25 Size >= 7 && Eq(Data + 7, Size - 7, "ZXCVN") &&
26 Size >= 14 && Data[13] == 42
27 ) {
28 fprintf(stderr, "BINGO\n");
29 exit(1);
30 }
31 return 0;
32 }