//===-- hashtable_fuzz.cpp ------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// /// /// Fuzzing test for llvm-libc hashtable implementations. /// //===----------------------------------------------------------------------===// #include "include/llvm-libc-types/ENTRY.h" #include "src/__support/CPP/string_view.h" #include "src/__support/HashTable/table.h" #include "src/__support/macros/config.h" namespace LIBC_NAMESPACE_DECL { // A fuzzing payload starts with // - uint16_t: initial capacity for table A // - uint64_t: seed for table A // - uint16_t: initial capacity for table B // - uint64_t: seed for table B // Followed by a sequence of actions: // - CrossCheck: only a single byte valued (4 mod 5) // - Find: a single byte valued (3 mod 5) followed by a null-terminated string // - Insert: a single byte valued (0,1,2 mod 5) followed by a null-terminated // string static constexpr size_t INITIAL_HEADER_SIZE = …; extern "C" size_t LLVMFuzzerMutate(uint8_t *data, size_t size, size_t max_size); extern "C" size_t LLVMFuzzerCustomMutator(uint8_t *data, size_t size, size_t max_size, unsigned int seed) { … } // a tagged union struct Action { … }; static struct { … } global_status; class HashTable { … }; HashTable next_hashtable() { … } extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { … } } // namespace LIBC_NAMESPACE_DECL