From 0b6210cd37b68b94252cb798598b12974a20e1c1 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Tue, 21 May 2024 22:56:19 +0200 Subject: Adding upstream version 5.28.2+dfsg1+~cs23.11.12.3. Signed-off-by: Daniel Baumann --- llhttp/test/fuzzers/fuzz_parser.c | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 llhttp/test/fuzzers/fuzz_parser.c (limited to 'llhttp/test/fuzzers/fuzz_parser.c') diff --git a/llhttp/test/fuzzers/fuzz_parser.c b/llhttp/test/fuzzers/fuzz_parser.c new file mode 100644 index 0000000..60d00ae --- /dev/null +++ b/llhttp/test/fuzzers/fuzz_parser.c @@ -0,0 +1,45 @@ +#include "llhttp.h" +#include +#include +#include + +int handle_on_message_complete(llhttp_t *arg) { return 0; } + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + llhttp_t parser; + llhttp_settings_t settings; + llhttp_type_t http_type; + + /* We need four bytes to determine variable parameters */ + if (size < 4) { + return 0; + } + + int headers = (data[0] & 0x01) == 1; + int chunked_length = (data[1] & 0x01) == 1; + int keep_alive = (data[2] & 0x01) == 1; + if (data[0] % 3 == 0) { + http_type = HTTP_BOTH; + } else if (data[0] % 3 == 1) { + http_type = HTTP_REQUEST; + } else { + http_type = HTTP_RESPONSE; + } + data += 4; + size -= 4; + + /* Initialize user callbacks and settings */ + llhttp_settings_init(&settings); + + /* Set user callback */ + settings.on_message_complete = handle_on_message_complete; + + llhttp_init(&parser, http_type, &settings); + llhttp_set_lenient_headers(&parser, headers); + llhttp_set_lenient_chunked_length(&parser, chunked_length); + llhttp_set_lenient_keep_alive(&parser, keep_alive); + + llhttp_execute(&parser, data, size); + + return 0; +} -- cgit v1.2.3