curl-fuzzer C++ reference
Loading...
Searching...
No Matches
proto_fuzzer::UploadScriptState Class Reference

Cursor and policy behind the request read/seek callbacks. More...

#include <request_data.h>

Public Types

using BeforeReadCallback = void (*)(void*)
 C-compatible hook invoked immediately before each read result is chosen.

Public Member Functions

 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.
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 allocation-free fallback.
int Seek (curl_off_t requested_offset, int origin)
 Apply the configured seek outcome and, for OK, move the bounded cursor.
std::size_t data_size () const
std::size_t read_step_count () const
std::size_t offset () const
std::size_t seek_calls () const
bool scripted () const
CURLcode InstallAsMimePart (curl_mimepart *part)
 Install the same bounded read/seek cursor behind a public MIME callback part.

Detailed Description

Cursor and policy behind the request read/seek callbacks.

Keeping it per RunScenario invocation avoids the file-static state that made nested or concurrent reproductions share an upload cursor, and gives retry paths a real rewindable source rather than stdin.

Definition at line 31 of file request_data.h.

Member Typedef Documentation

◆ BeforeReadCallback

C-compatible hook invoked immediately before each read result is chosen.

TELNET uses it to drain replies while curl's synchronous protocol loop prevents the outer mock driver from running.

Definition at line 36 of file request_data.h.

Constructor & Destructor Documentation

◆ UploadScriptState()

proto_fuzzer::UploadScriptState::UploadScriptState ( const curl::fuzzer::proto::Scenario & scenario)
explicit

Borrow and cap a scripted upload source before libcurl receives a userdata pointer.

When Scenario.upload is absent, non-TELNET schemes synthesize the historical 16 KiB U stream without allocating it, while TELNET reports immediate EOF so merely selecting the protocol cannot inject unsolicited terminal input. Borrowing avoids duplicating every fuzzed body before curl can read it; scenario must remain alive and unmodified until this state is destroyed.

Parameters
scenarioSource and lifetime owner of callback bytes and outcomes.

Definition at line 272 of file request_data.cc.

Member Function Documentation

◆ data_size()

std::size_t proto_fuzzer::UploadScriptState::data_size ( ) const
Returns
Number of bytes visible to the callback after caps.

Definition at line 439 of file request_data.cc.

◆ InstallAsMimePart()

CURLcode proto_fuzzer::UploadScriptState::InstallAsMimePart ( curl_mimepart * part)

Install the same bounded read/seek cursor behind a public MIME callback part.

curl retains this until the MIME root is freed, so ScenarioRequestData declares the root after the state and detaches it before either is released.

Parameters
partMIME part owned by the caller's live root.
Returns
libcurl's setup result.

Definition at line 458 of file request_data.cc.

◆ offset()

std::size_t proto_fuzzer::UploadScriptState::offset ( ) const
Returns
Current byte cursor, exposed for deterministic unit tests.

Definition at line 445 of file request_data.cc.

◆ Read()

std::size_t proto_fuzzer::UploadScriptState::Read ( char * buffer,
std::size_t capacity )

Copy the next bounded chunk and advance the cursor, using either the explicit payload or the allocation-free fallback.

Terminal outcomes are emitted only after all data is consumed so a mutation can independently control fragmentation and completion policy. Public so focused tests can validate callback semantics without relying on HTTP timing.

Parameters
bufferDestination supplied by curl.
capacityWritable bytes in buffer.
Returns
Bytes copied, zero for EOF, CURL_READFUNC_ABORT, or the TELNET- only CURL_READFUNC_PAUSE outcome.

Definition at line 327 of file request_data.cc.

◆ read_step_count()

std::size_t proto_fuzzer::UploadScriptState::read_step_count ( ) const
Returns
Number of retained per-read limits after caps.

Definition at line 442 of file request_data.cc.

◆ scripted()

bool proto_fuzzer::UploadScriptState::scripted ( ) const
Returns
Whether Scenario.upload was present instead of using fallback.

Definition at line 451 of file request_data.cc.

◆ Seek()

int proto_fuzzer::UploadScriptState::Seek ( curl_off_t requested_offset,
int origin )

Apply the configured seek outcome and, for OK, move the bounded cursor.

Successful seeks restart the short-read sequence so retries replay the same callback fragmentation deterministically. Explicit range checks model only seeks curl can meaningfully request from a bounded memory source, avoiding signed overflow or a mutation wrapping into an in-bounds cursor.

Parameters
requested_offsetOffset interpreted relative to origin.
originOne of SEEK_SET, SEEK_CUR, or SEEK_END.
Returns
A CURL_SEEKFUNC_* result.

Definition at line 372 of file request_data.cc.

◆ seek_calls()

std::size_t proto_fuzzer::UploadScriptState::seek_calls ( ) const
Returns
Number of times libcurl asked the upload source to seek.

Definition at line 448 of file request_data.cc.


The documentation for this class was generated from the following files: