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. 5c5f01b2fSopenharmony_ci// Try to find the target using the indirect caller-callee pairs. 6c5f01b2fSopenharmony_ci#include <cstdint> 7c5f01b2fSopenharmony_ci#include <cstdlib> 8c5f01b2fSopenharmony_ci#include <cstddef> 9c5f01b2fSopenharmony_ci#include <cstring> 10c5f01b2fSopenharmony_ci#include <iostream> 11c5f01b2fSopenharmony_ci 12c5f01b2fSopenharmony_citypedef void (*F)(); 13c5f01b2fSopenharmony_cistatic F t[256]; 14c5f01b2fSopenharmony_ci 15c5f01b2fSopenharmony_civoid f34() { 16c5f01b2fSopenharmony_ci std::cerr << "BINGO\n"; 17c5f01b2fSopenharmony_ci exit(1); 18c5f01b2fSopenharmony_ci} 19c5f01b2fSopenharmony_civoid f23() { t[(unsigned)'d'] = f34;} 20c5f01b2fSopenharmony_civoid f12() { t[(unsigned)'c'] = f23;} 21c5f01b2fSopenharmony_civoid f01() { t[(unsigned)'b'] = f12;} 22c5f01b2fSopenharmony_civoid f00() {} 23c5f01b2fSopenharmony_ci 24c5f01b2fSopenharmony_cistatic F t0[256] = { 25c5f01b2fSopenharmony_ci f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, 26c5f01b2fSopenharmony_ci f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, 27c5f01b2fSopenharmony_ci f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, 28c5f01b2fSopenharmony_ci f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, 29c5f01b2fSopenharmony_ci f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, 30c5f01b2fSopenharmony_ci f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, 31c5f01b2fSopenharmony_ci f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, 32c5f01b2fSopenharmony_ci f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, 33c5f01b2fSopenharmony_ci f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, 34c5f01b2fSopenharmony_ci f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, 35c5f01b2fSopenharmony_ci f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, 36c5f01b2fSopenharmony_ci f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, 37c5f01b2fSopenharmony_ci f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, 38c5f01b2fSopenharmony_ci f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, 39c5f01b2fSopenharmony_ci f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, 40c5f01b2fSopenharmony_ci f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, 41c5f01b2fSopenharmony_ci}; 42c5f01b2fSopenharmony_ci 43c5f01b2fSopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 44c5f01b2fSopenharmony_ci if (Size < 4) return 0; 45c5f01b2fSopenharmony_ci // Spoof the counters. 46c5f01b2fSopenharmony_ci for (int i = 0; i < 200; i++) { 47c5f01b2fSopenharmony_ci f23(); 48c5f01b2fSopenharmony_ci f12(); 49c5f01b2fSopenharmony_ci f01(); 50c5f01b2fSopenharmony_ci } 51c5f01b2fSopenharmony_ci memcpy(t, t0, sizeof(t)); 52c5f01b2fSopenharmony_ci t[(unsigned)'a'] = f01; 53c5f01b2fSopenharmony_ci t[Data[0]](); 54c5f01b2fSopenharmony_ci t[Data[1]](); 55c5f01b2fSopenharmony_ci t[Data[2]](); 56c5f01b2fSopenharmony_ci t[Data[3]](); 57c5f01b2fSopenharmony_ci return 0; 58c5f01b2fSopenharmony_ci} 59c5f01b2fSopenharmony_ci 60