Changeset View
Changeset View
Standalone View
Standalone View
src/test/fuzz/http_request.cpp
// Copyright (c) 2020 The Bitcoin Core developers | // Copyright (c) 2020 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <httpserver.h> | #include <httpserver.h> | ||||
#include <netaddress.h> | #include <netaddress.h> | ||||
#include <test/fuzz/FuzzedDataProvider.h> | #include <test/fuzz/FuzzedDataProvider.h> | ||||
#include <test/fuzz/fuzz.h> | #include <test/fuzz/fuzz.h> | ||||
#include <test/fuzz/util.h> | #include <test/fuzz/util.h> | ||||
#include <event2/buffer.h> | #include <event2/buffer.h> | ||||
#include <event2/event.h> | |||||
#include <event2/http.h> | #include <event2/http.h> | ||||
#include <event2/http_struct.h> | #include <event2/http_struct.h> | ||||
#include <cassert> | #include <cassert> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <string> | #include <string> | ||||
#include <vector> | #include <vector> | ||||
// workaround for libevent versions before 2.1.1, | |||||
// when internal functions didn't have underscores at the end | |||||
#if LIBEVENT_VERSION_NUMBER < 0x02010100 | |||||
extern "C" int evhttp_parse_firstline(struct evhttp_request *, | |||||
struct evbuffer *); | |||||
extern "C" int evhttp_parse_headers(struct evhttp_request *, struct evbuffer *); | |||||
inline int evhttp_parse_firstline_(struct evhttp_request *r, | |||||
struct evbuffer *b) { | |||||
return evhttp_parse_firstline(r, b); | |||||
} | |||||
inline int evhttp_parse_headers_(struct evhttp_request *r, struct evbuffer *b) { | |||||
return evhttp_parse_headers(r, b); | |||||
} | |||||
#else | |||||
extern "C" int evhttp_parse_firstline_(struct evhttp_request *, | extern "C" int evhttp_parse_firstline_(struct evhttp_request *, | ||||
struct evbuffer *); | struct evbuffer *); | ||||
extern "C" int evhttp_parse_headers_(struct evhttp_request *, | extern "C" int evhttp_parse_headers_(struct evhttp_request *, | ||||
struct evbuffer *); | struct evbuffer *); | ||||
#endif | |||||
std::string RequestMethodString(HTTPRequest::RequestMethod m); | std::string RequestMethodString(HTTPRequest::RequestMethod m); | ||||
void test_one_input(const std::vector<uint8_t> &buffer) { | void test_one_input(const std::vector<uint8_t> &buffer) { | ||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()}; | FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()}; | ||||
evhttp_request *evreq = evhttp_request_new(nullptr, nullptr); | evhttp_request *evreq = evhttp_request_new(nullptr, nullptr); | ||||
assert(evreq != nullptr); | assert(evreq != nullptr); | ||||
evreq->kind = EVHTTP_REQUEST; | evreq->kind = EVHTTP_REQUEST; | ||||
evbuffer *evbuf = evbuffer_new(); | evbuffer *evbuf = evbuffer_new(); | ||||
Show All 31 Lines |