diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
commit | 0b6210cd37b68b94252cb798598b12974a20e1c1 (patch) | |
tree | e371686554a877842d95aa94f100bee552ff2a8e /llhttp/test/fuzzers | |
parent | Initial commit. (diff) | |
download | node-undici-upstream.tar.xz node-undici-upstream.zip |
Adding upstream version 5.28.2+dfsg1+~cs23.11.12.3.upstream/5.28.2+dfsg1+_cs23.11.12.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'llhttp/test/fuzzers')
-rw-r--r-- | llhttp/test/fuzzers/fuzz_parser.c | 45 |
1 files changed, 45 insertions, 0 deletions
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 <stdio.h> +#include <stdlib.h> +#include <string.h> + +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; +} |