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 several narrow ranges. 5c5f01b2fSopenharmony_ci#include <cstdint> 6c5f01b2fSopenharmony_ci#include <cstdlib> 7c5f01b2fSopenharmony_ci#include <cstring> 8c5f01b2fSopenharmony_ci#include <cstdio> 9c5f01b2fSopenharmony_ci 10c5f01b2fSopenharmony_ciextern int AllLines[]; 11c5f01b2fSopenharmony_ci 12c5f01b2fSopenharmony_cibool PrintOnce(int Line) { 13c5f01b2fSopenharmony_ci if (!AllLines[Line]) 14c5f01b2fSopenharmony_ci fprintf(stderr, "Seen line %d\n", Line); 15c5f01b2fSopenharmony_ci AllLines[Line] = 1; 16c5f01b2fSopenharmony_ci return true; 17c5f01b2fSopenharmony_ci} 18c5f01b2fSopenharmony_ci 19c5f01b2fSopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 20c5f01b2fSopenharmony_ci if (Size != 22) return 0; 21c5f01b2fSopenharmony_ci uint64_t x = 0; 22c5f01b2fSopenharmony_ci int64_t y = 0; 23c5f01b2fSopenharmony_ci int32_t z = 0; 24c5f01b2fSopenharmony_ci uint16_t a = 0; 25c5f01b2fSopenharmony_ci memcpy(&x, Data, 8); // 8 26c5f01b2fSopenharmony_ci memcpy(&y, Data + 8, 8); // 16 27c5f01b2fSopenharmony_ci memcpy(&z, Data + 16, sizeof(z)); // 20 28c5f01b2fSopenharmony_ci memcpy(&a, Data + 20, sizeof(a)); // 22 29c5f01b2fSopenharmony_ci 30c5f01b2fSopenharmony_ci if (x > 1234567890 && PrintOnce(__LINE__) && 31c5f01b2fSopenharmony_ci x < 1234567895 && PrintOnce(__LINE__) && 32c5f01b2fSopenharmony_ci a == 0x4242 && PrintOnce(__LINE__) && 33c5f01b2fSopenharmony_ci y >= 987654321 && PrintOnce(__LINE__) && 34c5f01b2fSopenharmony_ci y <= 987654325 && PrintOnce(__LINE__) && 35c5f01b2fSopenharmony_ci z < -10000 && PrintOnce(__LINE__) && 36c5f01b2fSopenharmony_ci z >= -10005 && PrintOnce(__LINE__) && 37c5f01b2fSopenharmony_ci z != -10003 && PrintOnce(__LINE__) && 38c5f01b2fSopenharmony_ci true) { 39c5f01b2fSopenharmony_ci fprintf(stderr, "BINGO; Found the target: size %zd (%zd, %zd, %d, %d), exiting.\n", 40c5f01b2fSopenharmony_ci Size, x, y, z, a); 41c5f01b2fSopenharmony_ci exit(1); 42c5f01b2fSopenharmony_ci } 43c5f01b2fSopenharmony_ci return 0; 44c5f01b2fSopenharmony_ci} 45c5f01b2fSopenharmony_ci 46c5f01b2fSopenharmony_ciint AllLines[__LINE__ + 1]; // Must be the last line. 47