|
curl-fuzzer C++ reference
|
Owns one half of a socketpair used to feed canned responses to libcurl. More...
Public Member Functions | |
| MockConnection () | |
| Construct a non-blocking AF_UNIX/SOCK_STREAM socketpair. | |
| virtual | ~MockConnection () |
| Close the server-side fd (and the client-side fd if it was never handed off via take_client_fd()). | |
| virtual bool | ok () const |
| curl_socket_t | take_client_fd () |
| Hand the client-side fd to libcurl. | |
| int | server_fd () const |
| std::size_t | client_send_buffer_size () const |
| Query the capacity curl's endpoint reports for queued client writes while this object still owns that endpoint. | |
| bool | EnsureClientSendBufferSize (std::size_t minimum) |
| Ensure curl's endpoint reports at least minimum bytes of send buffer, requesting a larger SO_SNDBUF when the platform default is smaller. | |
| bool | FillClientSendBuffer () |
| Saturate curl's endpoint before ownership is transferred. | |
| virtual bool | WriteAll (const unsigned char *data, std::size_t size) |
| Write 'size' bytes from 'data' to the server fd, looping until the whole buffer is sent or a short/failed write occurs. | |
| virtual std::size_t | DrainIncoming () |
| Advance incoming transport work according to the configured per-call limit. | |
| void | SetIncomingDataObserver (IncomingDataObserver *observer) |
| Register a non-owning sink for bytes consumed from curl. | |
| void | ReadAvailable (std::string *out) |
| Non-blocking read: append whatever bytes are currently available on the server fd to 'out'. | |
| virtual void | ShutdownWrite () |
| Signal end-of-response to libcurl by half-closing the write side. | |
| void | ApplyBackpressure (int recv_buf_bytes, std::size_t drain_limit) |
| Apply deterministic backpressure knobs before traffic begins. | |
Protected Member Functions | |
| MockConnection (int adopted_server_fd) | |
| Adopt one connected descriptor as this peer's server endpoint. | |
| void | NotifyIncomingData (const unsigned char *data, std::size_t size) |
| Forward one application-data fragment to the optional observer. | |
Owns one half of a socketpair used to feed canned responses to libcurl.
The destructor closes the server-side fd; the client-side fd is handed to libcurl via CURLOPT_OPENSOCKETFUNCTION and becomes curl's to close.
Definition at line 29 of file mock_server.h.
| proto_fuzzer::MockConnection::MockConnection | ( | ) |
Construct a non-blocking AF_UNIX/SOCK_STREAM socketpair.
Both fds are validated to fit inside FD_SETSIZE; on any failure ok() returns false and the instance is unusable.
Definition at line 58 of file mock_server.cc.
|
explicitprotected |
Adopt one connected descriptor as this peer's server endpoint.
This path lets real loopback listeners reuse the bounded transport machinery without manufacturing a socketpair whose client endpoint curl cannot inherit.
| adopted_server_fd | Connected descriptor whose ownership transfers. |
Definition at line 89 of file mock_server.cc.
| void proto_fuzzer::MockConnection::ApplyBackpressure | ( | int | recv_buf_bytes, |
| std::size_t | drain_limit ) |
Apply deterministic backpressure knobs before traffic begins.
A positive recv_buf_bytes sets SO_RCVBUF on the server fd and SO_SNDBUF on the client fd, which this object still owns, to make curl short-write or see EAGAIN. Linux socketpairs effectively use max(SNDBUF, RCVBUF*2) as pipe capacity, so both settings are needed to produce short writes reliably. Cap each DrainIncoming call at drain_limit bytes; zero leaves the drain unlimited.
| recv_buf_bytes | SO_RCVBUF size in bytes, or 0 to leave default. |
| drain_limit | Max bytes drained per DrainIncoming call, 0 for unlimited. |
Definition at line 272 of file mock_server.cc.
| std::size_t proto_fuzzer::MockConnection::client_send_buffer_size | ( | ) | const |
Query the capacity curl's endpoint reports for queued client writes while this object still owns that endpoint.
Synchronous protocol mocks use this before transferring fd ownership because they cannot rely on the outer driver to make room. A zero result covers both an invalid fd and a platform query failure; callers need a verified capacity before proceeding.
Definition at line 123 of file mock_server.cc.
|
virtual |
Advance incoming transport work according to the configured per-call limit.
This plaintext implementation reports bytes consumed; layered transports may also report handshake state changes so the bounded outer loop does not mistake useful protocol progress for an idle connection. When a backpressure drain limit has been applied (see ApplyBackpressure), stop after drain_limit_ bytes so the kernel recv buffer stays near-full and curl keeps seeing short writes. Otherwise drain until read() returns 0/EAGAIN, matching legacy behaviour.
Definition at line 225 of file mock_server.cc.
| bool proto_fuzzer::MockConnection::EnsureClientSendBufferSize | ( | std::size_t | minimum | ) |
Ensure curl's endpoint reports at least minimum bytes of send buffer, requesting a larger SO_SNDBUF when the platform default is smaller.
Linux may transform socket-buffer requests, so the post-set query establishes the contract rather than assuming setsockopt accepted the exact value.
| minimum | Smallest acceptable reported capacity in bytes. |
Definition at line 141 of file mock_server.cc.
| bool proto_fuzzer::MockConnection::FillClientSendBuffer | ( | ) |
Saturate curl's endpoint before ownership is transferred.
The temporary non-blocking flag makes the stopping condition explicit and is restored so curl receives the same descriptor state as every other stream peer.
Definition at line 159 of file mock_server.cc.
|
protected |
Forward one application-data fragment to the optional observer.
| data | First byte of the fragment. |
| size | Number of bytes available at data. |
Definition at line 258 of file mock_server.cc.
|
virtual |
Definition at line 112 of file mock_server.cc.
| void proto_fuzzer::MockConnection::ReadAvailable | ( | std::string * | out | ) |
Non-blocking read: append whatever bytes are currently available on the server fd to 'out'.
Used by the WS handshake path to collect curl's HTTP Upgrade request without losing any bytes.
| out | Destination buffer; unchanged if no bytes are pending. |
Definition at line 288 of file mock_server.cc.
| int proto_fuzzer::MockConnection::server_fd | ( | ) | const |
Definition at line 115 of file mock_server.cc.
| void proto_fuzzer::MockConnection::SetIncomingDataObserver | ( | IncomingDataObserver * | observer | ) |
Register a non-owning sink for bytes consumed from curl.
TLS transports notify it after decryption, while plaintext transports report socket bytes directly. The observer must outlive this connection.
| observer | Observer to notify, or nullptr to disable observation. |
Definition at line 253 of file mock_server.cc.
| curl_socket_t proto_fuzzer::MockConnection::take_client_fd | ( | ) |
Hand the client-side fd to libcurl.
After this call the caller owns the fd and the MockConnection will not close it on destruction.
Definition at line 187 of file mock_server.cc.
|
virtual |
Write 'size' bytes from 'data' to the server fd, looping until the whole buffer is sent or a short/failed write occurs.
MSG_NOSIGNAL is a harness invariant rather than a curl behavior choice: a response race may leave the peer closed, and that must look like an ordinary failed mock write instead of terminating the fuzz process with SIGPIPE.
| data | Buffer to send. |
| size | Number of bytes in 'data'. |
Definition at line 201 of file mock_server.cc.