curl-fuzzer C++ reference
Loading...
Searching...
No Matches
request_data.h
Go to the documentation of this file.
1/*
2 * Copyright (C) Max Dymond, <cmeister2@gmail.com>, et al.
3 *
4 * SPDX-License-Identifier: curl
5 */
6
10
11#ifndef PROTO_FUZZER_REQUEST_DATA_H_
12#define PROTO_FUZZER_REQUEST_DATA_H_
13
14#include <curl/curl.h>
15
16#include <array>
17#include <cstddef>
18#include <cstdint>
19#include <string_view>
20
21#include "curl_fuzzer.pb.h"
24
25namespace proto_fuzzer {
26
32 public:
36 using BeforeReadCallback = void (*)(void*);
37
38 explicit UploadScriptState(const curl::fuzzer::proto::Scenario& scenario);
39
41 UploadScriptState(curl::fuzzer::proto::Scenario&& scenario) = delete;
42 UploadScriptState(const curl::fuzzer::proto::Scenario&& scenario) = delete;
43
44 std::size_t Read(char* buffer, std::size_t capacity);
45
46 int Seek(curl_off_t requested_offset, int origin);
47
48 std::size_t data_size() const;
49
50 std::size_t read_step_count() const;
51
52 std::size_t offset() const;
53
54 std::size_t seek_calls() const;
55
56 bool scripted() const;
57
58 CURLcode InstallAsMimePart(curl_mimepart* part);
59
60 private:
61 friend class ScenarioRequestData;
62
63 void SetBeforeReadCallback(BeforeReadCallback callback, void* userdata);
64
65 static std::size_t ReadCallback(char* buffer, std::size_t size, std::size_t nitems, void* userdata);
66
67 static int SeekCallback(void* userdata, curl_off_t offset, int origin);
68
69 std::string_view data_;
70 std::array<std::size_t, scenario_limits::kMaxUploadReadSteps> read_sizes_;
71 std::size_t read_step_count_;
72 std::size_t total_size_;
73 std::size_t max_read_size_;
74 std::size_t offset_;
75 std::size_t next_read_size_;
76 std::size_t seek_calls_;
77 curl::fuzzer::proto::UploadTerminal terminal_;
78 curl::fuzzer::proto::UploadSeekResult seek_result_;
79 BeforeReadCallback before_read_callback_;
80 void* before_read_userdata_;
81 bool scripted_;
82};
83
89 std::size_t request_headers = 0;
92 std::size_t resolve_entries = 0;
94 std::size_t telnet_options = 0;
96 std::size_t mail_rcpt = 0;
98 std::size_t mime_parts = 0;
100 std::size_t mime_callback_parts = 0;
102 std::size_t mime_headers = 0;
104 std::size_t generated_mime_bytes = 0;
105};
106
113 public:
114 ScenarioRequestData(CURL* easy, const curl::fuzzer::proto::Scenario& scenario, bool apply_resolve_entries = false);
115
117 ScenarioRequestData(CURL* easy, curl::fuzzer::proto::Scenario&& scenario,
118 bool apply_resolve_entries = false) = delete;
119 ScenarioRequestData(CURL* easy, const curl::fuzzer::proto::Scenario&& scenario,
120 bool apply_resolve_entries = false) = delete;
121
123
125 ScenarioRequestData& operator=(const ScenarioRequestData&) = delete;
126
127 const RequestBuildStats& stats() const;
128
129 const UploadScriptState& upload_state() const;
130
131 bool upload_callbacks_installed() const;
132
133 bool resolve_entries_ready() const;
134
136
137 private:
138 CURL* easy_;
139 CurlSlistPtr request_headers_;
140 CurlSlistPtr resolve_entries_;
141 CurlSlistPtr telnet_options_;
142 CurlSlistPtr mail_rcpt_;
143 UploadScriptState upload_state_;
144 // Declared after upload_state_ so the MIME root releases its retained
145 // callback userdata before the cursor is destroyed.
146 CurlMimePtr mime_post_;
147 bool upload_callbacks_installed_;
148 bool resolve_entries_ready_;
149 RequestBuildStats stats_;
150};
151
152} // namespace proto_fuzzer
153
154#endif // PROTO_FUZZER_REQUEST_DATA_H_
ScenarioRequestData(CURL *easy, curl::fuzzer::proto::Scenario &&scenario, bool apply_resolve_entries=false)=delete
A temporary Scenario cannot outlive the upload view retained for curl.
~ScenarioRequestData()
Detach pointer options/callbacks while the easy handle is valid, then release request allocations.
const RequestBuildStats & stats() const
Return resource counts after caps and allocation failures were applied, without exposing or transferr...
const UploadScriptState & upload_state() const
Return the callback state retained for the complete drive.
bool resolve_entries_ready() const
Return whether resolver-only slist construction installed its mandatory final loopback mapping.
void SetBeforeUploadReadCallback(UploadScriptState::BeforeReadCallback callback, void *userdata)
Arrange protocol-specific work immediately before every upload read.
bool upload_callbacks_installed() const
Return whether this scenario needed raw upload callbacks.
ScenarioRequestData(CURL *easy, const curl::fuzzer::proto::Scenario &scenario, bool apply_resolve_entries=false)
Construct and apply the protocol-specific pointer-valued fields in scenario to easy.
Cursor and policy behind the request read/seek callbacks.
std::size_t Read(char *buffer, std::size_t capacity)
Copy the next bounded chunk and advance the cursor, using either the explicit payload or the allocati...
int Seek(curl_off_t requested_offset, int origin)
Apply the configured seek outcome and, for OK, move the bounded cursor.
CURLcode InstallAsMimePart(curl_mimepart *part)
Install the same bounded read/seek cursor behind a public MIME callback part.
std::size_t read_step_count() const
UploadScriptState(const curl::fuzzer::proto::Scenario &scenario)
Borrow and cap a scripted upload source before libcurl receives a userdata pointer.
UploadScriptState(curl::fuzzer::proto::Scenario &&scenario)=delete
A temporary Scenario cannot satisfy the borrowed payload's lifetime.
void(*)(void *) BeforeReadCallback
C-compatible hook invoked immediately before each read result is chosen.
Common ownership types for independently cleaned-up curl handles.
std::unique_ptr< curl_slist, CurlSlistDeleter > CurlSlistPtr
Unique ownership of a caller-owned curl_slist.
Definition curl_raii.h:60
std::unique_ptr< curl_mime, CurlMimeDeleter > CurlMimePtr
Unique ownership of a caller-owned curl_mime tree.
Definition curl_raii.h:62
Shared complexity limits for structured scenarios.
Counts the resources that survived allocation and runtime budgets.
std::size_t generated_mime_bytes
Materialized bytes supplied by compact generated MIME sources.
std::size_t telnet_options
Number of CURLOPT_TELNETOPTIONS entries retained.
std::size_t mime_parts
Number of top-level and nested curl_mimepart objects constructed.
std::size_t request_headers
Number of top-level CURLOPT_HTTPHEADER entries retained.
std::size_t mime_callback_parts
Number of top-level parts backed by Scenario.upload callbacks.
std::size_t mime_headers
Number of per-part header entries transferred to curl MIME ownership.
std::size_t mail_rcpt
Number of SMTP recipients retained in the CURLOPT_MAIL_RCPT list.
std::size_t resolve_entries
Number of fuzzed CURLOPT_RESOLVE entries retained before the fixed loopback mapping was appended.