curl-fuzzer C++ reference
Loading...
Searching...
No Matches
pop3_mock_server.cc
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
9
11
12#include <string>
13#include <string_view>
14
15#include "proto_fuzzer/allocation_fault_injection.h"
16
17namespace proto_fuzzer {
18
23
28
33void Pop3MockServer::HandleLine(std::string_view line) {
34 if (scenario() == nullptr) {
35 return;
36 }
37 const std::string* response = NextControlReply();
38 if (response == nullptr || !WriteControlBytes(*response)) {
39 return;
40 }
41 if (!scenario()->pop3_starttls_filter_allocation_failure()) {
42 return;
43 }
44 const bool starttls_accepted = TokenEquals(FirstToken(line), "STLS") && TokenEquals(FirstToken(*response), "+OK");
45 if (starttls_accepted) {
46 allocation_fault_injection::ArmNextAllocationFailure();
47 }
48}
49
54
57#if defined(PROTO_FUZZER_OBSERVE_STATE)
59 const volatile std::size_t pop3_observation[] = {control_transcript().size(), uploaded_data().size()};
60 (void)pop3_observation;
61#endif
62}
63
64} // namespace proto_fuzzer
virtual void ObserveState()
Default no-op for peers without protocol-specific observations.
const std::string & control_transcript() const
Expose the bounded command capture from the most recent drive so tests can verify protocol states wit...
const curl::fuzzer::proto::Scenario * scenario() const
Borrowed scenario for the synchronous drive, or nullptr outside RunLoop().
static std::string_view FirstToken(std::string_view line)
Remove optional leading horizontal whitespace and return the first token without allocating.
const std::string * NextControlReply()
Return the next command-aligned response within the shared response-count budget.
const std::string & uploaded_data() const
Expose a bounded prefix of bytes drained during the most recent body phase while continuing to drain ...
static bool TokenEquals(std::string_view token, std::string_view expected_uppercase)
Fold only ASCII lowercase command letters.
bool WriteControlBytes(std::string_view bytes)
Keep failed peer writes local to the mock.
void QueueShutdownReply() override
Queue a +OK for the blocking QUIT that follows easy cleanup, then let the shared transport half-close...
void HandleLine(std::string_view line) override
Advance one reply for every complete command.
Pop3MockServer()
Begin without a borrowed protobuf or open socketpair.
~Pop3MockServer() override
Release the server-owned socketpair half after curl has returned its client descriptor.
void ObserveState() override
Retain protocol outcomes in coverage and introspector builds.
Command-aware in-process peer for curl's POP3 state machine.