From 17e81f2cd1843f01838245eae7b5ed5edf83d6be Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 09:30:55 +0200 Subject: Adding upstream version 0.12.1+dfsg. Signed-off-by: Daniel Baumann --- fuzz/ksl.cc | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 fuzz/ksl.cc (limited to 'fuzz/ksl.cc') diff --git a/fuzz/ksl.cc b/fuzz/ksl.cc new file mode 100644 index 0000000..9bbf4c4 --- /dev/null +++ b/fuzz/ksl.cc @@ -0,0 +1,77 @@ +#include + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ngtcp2_ksl.h" + +#ifdef __cplusplus +} +#endif + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + using KeyType = uint16_t; + using DataType = int64_t; + constexpr size_t keylen = sizeof(KeyType); + + auto compar = [](auto *lhs, auto *rhs) -> int { + return *static_cast(lhs) < + *static_cast(rhs); + }; + + ngtcp2_ksl ksl; + + ngtcp2_ksl_init(&ksl, compar, keylen, ngtcp2_mem_default()); + + for (; size >= keylen; ++data, --size) { + KeyType d; + + memcpy(&d, data, keylen); + + for (size_t i = 0; i < 2; ++i) { + auto add = (d & 0x8000) != 0; + auto key = static_cast(d & 0x7fff); + + if (add) { + auto data = std::make_unique(key); + auto rv = ngtcp2_ksl_insert(&ksl, nullptr, &key, data.get()); + if (rv != 0) { + continue; + } + + data.release(); + ngtcp2_ksl_lower_bound(&ksl, &key); + + continue; + } + + auto it = ngtcp2_ksl_lower_bound(&ksl, &key); + if (ngtcp2_ksl_it_end(&it)) { + continue; + } + + if (*static_cast(ngtcp2_ksl_it_key(&it)) != key) { + continue; + } + + delete static_cast(ngtcp2_ksl_it_get(&it)); + + ngtcp2_ksl_remove(&ksl, nullptr, &key); + + d = bswap_16(d); + } + } + + for (auto it = ngtcp2_ksl_begin(&ksl); !ngtcp2_ksl_it_end(&it); + ngtcp2_ksl_it_next(&it)) { + delete static_cast(ngtcp2_ksl_it_get(&it)); + } + + ngtcp2_ksl_free(&ksl); + + return 0; +} -- cgit v1.2.3