|
7 | 7 | #include <test/fuzz/FuzzedDataProvider.h>
|
8 | 8 | #include <test/fuzz/fuzz.h>
|
9 | 9 | #include <test/fuzz/util.h>
|
| 10 | +#include <util/strencodings.h> |
10 | 11 |
|
11 | 12 | #include <event2/buffer.h>
|
12 | 13 | #include <event2/event.h>
|
@@ -48,7 +49,14 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
48 | 49 | assert(evbuf != nullptr);
|
49 | 50 | const std::vector<uint8_t> http_buffer = ConsumeRandomLengthByteVector(fuzzed_data_provider, 4096);
|
50 | 51 | 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) { |
52 | 60 | evbuffer_free(evbuf);
|
53 | 61 | evhttp_request_free(evreq);
|
54 | 62 | return;
|
|
0 commit comments