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 the interesting switch value. 5c5f01b2fSopenharmony_ci#include <cstdint> 6c5f01b2fSopenharmony_ci#include <cstdlib> 7c5f01b2fSopenharmony_ci#include <cstdio> 8c5f01b2fSopenharmony_ci#include <cstring> 9c5f01b2fSopenharmony_ci#include <cstddef> 10c5f01b2fSopenharmony_ci 11c5f01b2fSopenharmony_cistatic volatile int Sink; 12c5f01b2fSopenharmony_ci 13c5f01b2fSopenharmony_citemplate<class T> 14c5f01b2fSopenharmony_cibool Switch(const uint8_t *Data, size_t Size) { 15c5f01b2fSopenharmony_ci T X; 16c5f01b2fSopenharmony_ci if (Size < sizeof(X)) return false; 17c5f01b2fSopenharmony_ci memcpy(&X, Data, sizeof(X)); 18c5f01b2fSopenharmony_ci switch (X) { 19c5f01b2fSopenharmony_ci case 1: Sink = __LINE__; break; 20c5f01b2fSopenharmony_ci case 101: Sink = __LINE__; break; 21c5f01b2fSopenharmony_ci case 1001: Sink = __LINE__; break; 22c5f01b2fSopenharmony_ci case 10001: Sink = __LINE__; break; 23c5f01b2fSopenharmony_ci// case 100001: Sink = __LINE__; break; 24c5f01b2fSopenharmony_ci// case 1000001: Sink = __LINE__; break; 25c5f01b2fSopenharmony_ci case 10000001: Sink = __LINE__; break; 26c5f01b2fSopenharmony_ci case 100000001: return true; 27c5f01b2fSopenharmony_ci } 28c5f01b2fSopenharmony_ci return false; 29c5f01b2fSopenharmony_ci} 30c5f01b2fSopenharmony_ci 31c5f01b2fSopenharmony_cibool ShortSwitch(const uint8_t *Data, size_t Size) { 32c5f01b2fSopenharmony_ci short X; 33c5f01b2fSopenharmony_ci if (Size < sizeof(short)) return false; 34c5f01b2fSopenharmony_ci memcpy(&X, Data, sizeof(short)); 35c5f01b2fSopenharmony_ci switch(X) { 36c5f01b2fSopenharmony_ci case 42: Sink = __LINE__; break; 37c5f01b2fSopenharmony_ci case 402: Sink = __LINE__; break; 38c5f01b2fSopenharmony_ci case 4002: Sink = __LINE__; break; 39c5f01b2fSopenharmony_ci case 5002: Sink = __LINE__; break; 40c5f01b2fSopenharmony_ci case 7002: Sink = __LINE__; break; 41c5f01b2fSopenharmony_ci case 9002: Sink = __LINE__; break; 42c5f01b2fSopenharmony_ci case 14002: Sink = __LINE__; break; 43c5f01b2fSopenharmony_ci case 21402: return true; 44c5f01b2fSopenharmony_ci } 45c5f01b2fSopenharmony_ci return false; 46c5f01b2fSopenharmony_ci} 47c5f01b2fSopenharmony_ci 48c5f01b2fSopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 49c5f01b2fSopenharmony_ci if (Size >= 4 && Switch<int>(Data, Size) && 50c5f01b2fSopenharmony_ci Size >= 12 && Switch<uint64_t>(Data + 4, Size - 4) && 51c5f01b2fSopenharmony_ci Size >= 14 && ShortSwitch(Data + 12, 2) 52c5f01b2fSopenharmony_ci ) { 53c5f01b2fSopenharmony_ci fprintf(stderr, "BINGO; Found the target, exiting\n"); 54c5f01b2fSopenharmony_ci exit(1); 55c5f01b2fSopenharmony_ci } 56c5f01b2fSopenharmony_ci return 0; 57c5f01b2fSopenharmony_ci} 58c5f01b2fSopenharmony_ci 59