Bitcoin Core 31.99.0
P2P Digital Currency
http_request.cpp
Go to the documentation of this file.
1// Copyright (c) 2020-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <httpserver.h>
6#include <netaddress.h>
8#include <test/fuzz/fuzz.h>
9#include <test/fuzz/util.h>
11#include <util/strencodings.h>
12
13#include <cassert>
14#include <cstdint>
15#include <string>
16#include <vector>
17
18
19std::string_view RequestMethodString(HTTPRequestMethod m);
20
21FUZZ_TARGET(http_request)
22{
25 using util::LineReader;
26
27 FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
28 const std::vector<std::byte> http_buffer{ConsumeRandomLengthByteVector<std::byte>(fuzzed_data_provider, 4096)};
29
30 HTTPRequest http_request;
31 LineReader reader(http_buffer, MAX_HEADERS_SIZE);
32 try {
33 if (!http_request.LoadControlData(reader)) return;
34 if (!http_request.LoadHeaders(reader)) return;
35 if (!http_request.LoadBody(reader)) return;
36 } catch (const std::runtime_error&) {
37 return;
38 }
39
40 const HTTPRequestMethod request_method = http_request.GetRequestMethod();
41 (void)RequestMethodString(request_method);
42 (void)http_request.GetURI();
43 (void)http_request.GetHeader("Host");
44 std::string header = fuzzed_data_provider.ConsumeRandomLengthString(16);
45 (void)http_request.GetHeader(header);
46 (void)http_request.WriteHeader(std::string(header), fuzzed_data_provider.ConsumeRandomLengthString(16));
47 (void)http_request.GetHeader(header);
48 const std::string body = http_request.ReadBody();
49 assert(body.empty());
50}
std::string ConsumeRandomLengthString(size_t max_length)
std::string_view RequestMethodString(HTTPRequestMethod m)
HTTP request method as string - use for logging only.
Definition: httpserver.cpp:115
FUZZ_TARGET(http_request)
HTTPRequestMethod
Definition: httpserver.h:45
util::LineReader reader
constexpr size_t MAX_HEADERS_SIZE
Maximum size of each headers line in an HTTP request, also the maximum size of all headers total.
Definition: httpserver.h:77
assert(!tx.IsCoinBase())
FuzzedDataProvider & fuzzed_data_provider
Definition: fees.cpp:39