Skip to content

Commit 20d31bd

Browse files
tests: Avoid fuzzer-specific nullptr dereference in libevent when handling PROXY requests
1 parent 9e8bd21 commit 20d31bd

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/test/fuzz/http_request.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <test/fuzz/FuzzedDataProvider.h>
88
#include <test/fuzz/fuzz.h>
99
#include <test/fuzz/util.h>
10+
#include <util/strencodings.h>
1011

1112
#include <event2/buffer.h>
1213
#include <event2/event.h>
@@ -48,7 +49,14 @@ void test_one_input(const std::vector<uint8_t>& buffer)
4849
assert(evbuf != nullptr);
4950
const std::vector<uint8_t> http_buffer = ConsumeRandomLengthByteVector(fuzzed_data_provider, 4096);
5051
evbuffer_add(evbuf, http_buffer.data(), http_buffer.size());
51-
if (evhttp_parse_firstline_(evreq, evbuf) != 1 || evhttp_parse_headers_(evreq, evbuf) != 1) {
52+
// Avoid constructing requests that will be interpreted by libevent as PROXY requests to avoid triggering
53+
// a nullptr dereference. The dereference (req->evcon->http_server) takes place in evhttp_parse_request_line
54+
// and is a consequence of our hacky but necessary use of the internal function evhttp_parse_firstline_ in
55+
// this fuzzing harness. The workaround is not aesthetically pleasing, but it successfully avoids the troublesome
56+
// code path. " http:// HTTP/1.1\n" was a crashing input prior to this workaround.
57+
const std::string http_buffer_str = ToLower({http_buffer.begin(), http_buffer.end()});
58+
if (http_buffer_str.find(" http://") != std::string::npos || http_buffer_str.find(" https://") != std::string::npos ||
59+
evhttp_parse_firstline_(evreq, evbuf) != 1 || evhttp_parse_headers_(evreq, evbuf) != 1) {
5260
evbuffer_free(evbuf);
5361
evhttp_request_free(evreq);
5462
return;

0 commit comments

Comments
 (0)