| 123456789101112131415161718192021222324252627282930313233343536 |
- #include <cstdint>
- #include "fuzzed_stream.h"
- namespace {
- void decode(const uint8_t *data, size_t size, size_t payload_max_length) {
- FuzzedStream strm(data, size);
- httplib::Response res;
- httplib::detail::read_content_chunked(
- strm, res, payload_max_length,
- [](const char *, size_t, uint64_t, uint64_t) { return true; });
- }
- } // namespace
- // The first decode initializes function-local statics, which in a persistent
- // fuzzer would otherwise show up as unstable coverage on the first input only.
- extern "C" int LLVMFuzzerInitialize(int * /*argc*/, char *** /*argv*/) {
- static const char warm_up[] =
- "5;ext=1\r\nhello\r\n0\r\nX-Trailer: 1\r\nExpires: 0\r\n\r\n";
- decode(reinterpret_cast<const uint8_t *>(warm_up), sizeof(warm_up) - 1, 0);
- return 0;
- }
- extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
- if (size < 2) { return 0; }
- // The first byte selects the payload limit, 0 meaning none
- static const size_t max_lens[] = {0, 1, 16, 4096,
- CPPHTTPLIB_PAYLOAD_MAX_LENGTH};
- auto n = sizeof(max_lens) / sizeof(max_lens[0]);
- decode(data + 1, size - 1, max_lens[data[0] % n]);
- return 0;
- }
|