1*92fb3101SKostya Serebryany // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2*92fb3101SKostya Serebryany // See https://llvm.org/LICENSE.txt for license information.
3*92fb3101SKostya Serebryany // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4*92fb3101SKostya Serebryany 
5*92fb3101SKostya Serebryany // Tests how the fuzzer rejects inputs if the target returns -1.
6*92fb3101SKostya Serebryany #include <cstddef>
7*92fb3101SKostya Serebryany #include <cstdint>
8*92fb3101SKostya Serebryany 
9*92fb3101SKostya Serebryany static volatile int Sink;
10*92fb3101SKostya Serebryany 
LLVMFuzzerTestOneInput(const uint8_t * Data,size_t Size)11*92fb3101SKostya Serebryany extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
12*92fb3101SKostya Serebryany   if (Size != 3)
13*92fb3101SKostya Serebryany     return -1; // Reject anyting that's not 3 bytes long.
14*92fb3101SKostya Serebryany   // Reject 'rej'.
15*92fb3101SKostya Serebryany   if (Data[0] == 'r' && Data[1] == 'e' && Data[2] == 'j')
16*92fb3101SKostya Serebryany     return -1;
17*92fb3101SKostya Serebryany   // Accept 'acc'.
18*92fb3101SKostya Serebryany   if (Data[0] == 'a' && Data[1] == 'c' && Data[2] == 'c') {
19*92fb3101SKostya Serebryany     Sink = 1;
20*92fb3101SKostya Serebryany     return 0;
21*92fb3101SKostya Serebryany   }
22*92fb3101SKostya Serebryany   return 0;
23*92fb3101SKostya Serebryany }
24