curl-fuzzer C++ reference
Loading...
Searching...
No Matches
proto_fuzzer::TelnetMockServer Class Referencefinal

Preloads a complete bounded TELNET response before curl enters its protocol loop. More...

#include <telnet_mock_server.h>

Inheritance diagram for proto_fuzzer::TelnetMockServer:
proto_fuzzer::MockServerBase

Public Member Functions

 TelnetMockServer ()
 Start without a borrowed scenario.
 ~TelnetMockServer () override
 The base owns and closes the server half after curl releases its client fd.
void ConfigureRequestData (ScenarioRequestData *request_data) override
 Attach the synchronous peer drain to TELNET's upload callback.
Public Member Functions inherited from proto_fuzzer::MockServerBase
virtual ~MockServerBase ()
 Out-of-line destructor so MockConnection can stay forward-declared in the base header (its complete type is only needed where unique_ptr is instantiated for destruction).
virtual void ObserveState ()
 Default no-op for peers without protocol-specific observations.
virtual void Install (CURL *easy)
 Install the common OPENSOCKETFUNCTION / OPENSOCKETDATA / SOCKOPTFUNCTION callbacks on 'easy'.
CURLcode DriveScenario (CURL *easy, const curl::fuzzer::proto::Scenario &scenario)
 Run 'scenario' to completion on 'easy': allocate a multi, attach 'easy', delegate protocol-specific work to RunLoop, consume its completion message, and clean up.
virtual CURLcode DriveEasyScenario (CURL *easy, const curl::fuzzer::proto::Scenario &scenario, bool use_events=false)
 Run through the public easy entrypoint when a protocol mock can preload all peer work before curl takes control.
virtual ConnectOnlyRunStats DriveConnectOnlyScenario (CURL *easy, const curl::fuzzer::proto::Scenario &scenario)
 Establish a CONNECT_ONLY transport, then perform bounded direct I/O.
void SetMultiObserver (MultiObserver observer)
 Register an observer invoked with the live multi handle after 'easy' is attached and before the drive loop starts.
MockConnection * connection ()

Protected Member Functions

curl_socket_t HandleOpenSocket (curlsocktype purpose=CURLSOCKTYPE_IPCXN, struct curl_sockaddr *address=nullptr) override
 Create one socketpair, preload every raw response fragment curl can observe, then half-close the peer before returning the client fd.
void RunLoop (CURLM *multi, CURL *easy, const curl::fuzzer::proto::Scenario &scenario) override
 Drive a small number of non-waiting multi transitions.
Protected Member Functions inherited from proto_fuzzer::MockServerBase
 MockServerBase (MultiDrivePolicy drive_policy=MultiDrivePolicy::kPerform)
 Construct an empty base instance with a fixed multi-drive policy.
virtual void HandleDetachedMulti (CurlMultiPtr multi)
 Dispose of or retain the multi after its easy handle has been removed.
virtual SocketSetupDisposition GetSocketSetupDisposition (curl_socket_t curlfd, curlsocktype purpose) const
 Describe the socket returned by HandleOpenSocket without issuing native descriptor queries.
MultiSocketDriver * multi_socket_driver ()
 Expose the callback state installed for the current socket-action drive.
std::size_t additional_handle_cleanup_count () const
void ResumeResponseIfRequested (CURL *easy)
 Resume receive-side callback output at one bounded drive boundary when the dedicated API plan requested it.
void ApplyPendingBackpressure ()
 Apply the BackpressureConfig cached by DriveScenario to the new connection_.

Additional Inherited Members

Public Types inherited from proto_fuzzer::MockServerBase
using MultiObserver = std::function<void(CURLM*)>
 Callback type used to publish the driving multi handle to observers.
Static Protected Member Functions inherited from proto_fuzzer::MockServerBase
static int WaitOnMultiFdset (CURLM *multi, CURLMcode *rc)
 Wait on curl's fdset with a short timeout.
static void ProbeMultiPollset (CURLM *multi)
 Ask curl to construct and inspect its connection-filter pollset without waiting.
static bool MultiPollsetWantsWrite (CURLM *multi, curl_socket_t socket)
 Inspect one socket's current writable interest through curl's public multi fdset API.
static bool UsesTimedDrive (const curl::fuzzer::proto::Scenario &scenario)
 Treat a non-default BackpressureConfig as an explicit request for the slower, timed drive policy.
Protected Attributes inherited from proto_fuzzer::MockServerBase
std::unique_ptr< MockConnection > connection_
 The per-scenario MockConnection, lazily created by HandleOpenSocket().
int pending_recv_buf_bytes_
 Cached SO_RCVBUF/SO_SNDBUF setting in bytes.
std::size_t pending_drain_limit_
 Cached per-call DrainIncoming byte budget.
MultiSocketDriver * multi_socket_driver_
 Non-owning pointer into DriveScenario's stack.
std::size_t additional_handle_cleanup_count_
 Number of application-created handles, excluding the caller's parent, successfully removed from the current multi and cleaned up.
bool resume_response_
 True only for an API-plan multi drive with its one-shot write callback.
MultiObserver multi_observer_
 Observer receiving the live multi handle at the start of a drive.
Static Protected Attributes inherited from proto_fuzzer::MockServerBase
static constexpr int kMaxDriveIterations = 512
 Hard operation budget for one scenario.
static constexpr int kMaxIdleIterations = 8
 Consecutive no-progress budget for ordinary scenarios.
static constexpr int kMaxTimedIdleIterations = 256
 Explicit backpressure scenarios get a larger idle budget and may use the short timed wait above.

Detailed Description

Preloads a complete bounded TELNET response before curl enters its protocol loop.

Unlike curl's event-driven HTTP path, telnet_do() polls the network and the caller's input source inside one curl_multi_perform() call. An incremental mock cannot regain control to provide its next chunk. This peer writes the whole runtime-visible script and half-closes first, making even an empty or malformed scenario immediately readable and preventing a fuzz iteration from waiting for terminal input or a wall-clock timeout.

Definition at line 30 of file telnet_mock_server.h.

Constructor & Destructor Documentation

◆ TelnetMockServer()

proto_fuzzer::TelnetMockServer::TelnetMockServer ( )

Start without a borrowed scenario.

RunLoop installs the pointer only for the synchronous multi drive in which curl may invoke HandleOpenSocket.

Definition at line 75 of file telnet_mock_server.cc.

Member Function Documentation

◆ ConfigureRequestData()

void proto_fuzzer::TelnetMockServer::ConfigureRequestData ( ScenarioRequestData * request_data)
overridevirtual

Attach the synchronous peer drain to TELNET's upload callback.

curl's TELNET driver does not yield to RunLoop between network parsing and callback writes, so this is the only cheap point at which the harness can keep the outbound socket empty.

Parameters
request_dataCallback state retained through the transfer.

Reimplemented from proto_fuzzer::MockServerBase.

Definition at line 85 of file telnet_mock_server.cc.

◆ HandleOpenSocket()

curl_socket_t proto_fuzzer::TelnetMockServer::HandleOpenSocket ( curlsocktype purpose = CURLSOCKTYPE_IPCXN,
struct curl_sockaddr * address = nullptr )
overrideprotectedvirtual

Create one socketpair, preload every raw response fragment curl can observe, then half-close the peer before returning the client fd.

TELNET's transfer function does not yield to the outer multi loop while it polls, so deferred delivery would turn an ordinary mutation into a timeout. WriteAll uses a non-blocking server fd; if a compatibility input exceeds the socket buffer, the retained prefix is still useful and the half-close still guarantees termination.

Parameters
purposeSocket role requested by curl; TELNET uses one outbound stream and does not need role-specific setup.
addressIntended destination retained by curl; the already-connected socketpair does not need to rewrite it.
Returns
The preloaded client socket, or CURL_SOCKET_BAD on setup failure.

Implements proto_fuzzer::MockServerBase.

Definition at line 111 of file telnet_mock_server.cc.

◆ RunLoop()

void proto_fuzzer::TelnetMockServer::RunLoop ( CURLM * multi,
CURL * easy,
const curl::fuzzer::proto::Scenario & scenario )
overrideprotectedvirtual

Drive a small number of non-waiting multi transitions.

The first call that enters telnet_do() sees a preloaded, half-closed peer and therefore returns without relying on the outer loop to deliver bytes. Subsequent calls only settle curl's completion bookkeeping.

Parameters
multiMulti handle whose sole easy handle runs the TELNET transfer.
easyEasy handle already installed on this mock.
scenarioBounded script to preload when curl opens its socket.

Implements proto_fuzzer::MockServerBase.

Definition at line 162 of file telnet_mock_server.cc.


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