curl-fuzzer C++ reference
Loading...
Searching...
No Matches
h2_plan.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
9
10#ifndef PROTO_FUZZER_H2_PLAN_H_
11#define PROTO_FUZZER_H2_PLAN_H_
12
13#include <cstddef>
14#include <cstdint>
15#include <string>
16#include <unordered_map>
17#include <vector>
18
19#include "curl_fuzzer.pb.h"
21
23struct nghttp2_hd_deflater;
24
25namespace proto_fuzzer {
26
30class H2PlanDriver final : public IncomingDataObserver {
31 public:
32 H2PlanDriver();
33 ~H2PlanDriver() override;
34
35 H2PlanDriver(const H2PlanDriver&) = delete;
36 H2PlanDriver& operator=(const H2PlanDriver&) = delete;
37
38 void Reset(const curl::fuzzer::proto::Http2Plan& plan, std::string scheme = "https",
39 std::string authority = "tls.test");
40
41 void ObserveIncomingData(const unsigned char* data, std::size_t size) override;
42
43 bool NextChunk(std::string* output);
44
45 bool has_pending_work() const;
46
47 std::size_t observed_request_count() const;
48
49 std::size_t observed_client_settings_count() const;
50
51 std::size_t observed_client_priority_count() const;
52
53 private:
54 struct ClientStreamState {
55 std::size_t headers = 0;
56 std::size_t data = 0;
57 std::size_t end_stream = 0;
58 };
59
60 std::uint32_t ResolveStream(const curl::fuzzer::proto::Http2StreamRef& stream, bool allow_connection) const;
61 std::uint32_t ResolvePromisedStream(const curl::fuzzer::proto::Http2StreamRef& stream);
62 bool WaitSatisfied(const curl::fuzzer::proto::Http2Wait& wait) const;
63 bool SerializeAction(const curl::fuzzer::proto::Http2Action& action, std::string* output);
64 bool EncodeHeaders(const std::vector<std::pair<std::string, std::string>>& headers, std::string* output);
65 void ParseClientFrames();
66 void RecordClientFrame(std::uint8_t type, std::uint8_t flags, std::uint32_t stream_id);
67
68 const curl::fuzzer::proto::Http2Plan* plan_;
69 nghttp2_hd_deflater* deflater_;
70 std::size_t next_action_;
71 std::size_t remaining_yields_;
72 bool initial_settings_sent_;
73 bool client_settings_ack_sent_;
74 bool expect_client_preface_;
75 std::size_t observed_client_settings_;
76 std::size_t observed_client_priority_;
77 std::string client_bytes_;
78 std::vector<std::uint32_t> request_streams_;
79 std::vector<std::uint32_t> pushed_streams_;
80 std::unordered_map<std::uint32_t, ClientStreamState> client_streams_;
81 std::string scheme_;
82 std::string authority_;
83};
84
85} // namespace proto_fuzzer
86
87#endif // PROTO_FUZZER_H2_PLAN_H_
bool has_pending_work() const
Definition h2_plan.cc:545
std::size_t observed_request_count() const
Definition h2_plan.cc:554
void ObserveIncomingData(const unsigned char *data, std::size_t size) override
Parse client frame headers after transport decoding.
Definition h2_plan.cc:158
std::size_t observed_client_priority_count() const
Definition h2_plan.cc:560
bool NextChunk(std::string *output)
Advance one scripted boundary.
Definition h2_plan.cc:489
std::size_t observed_client_settings_count() const
Definition h2_plan.cc:557
void Reset(const curl::fuzzer::proto::Http2Plan &plan, std::string scheme="https", std::string authority="tls.test")
Reset HPACK and stream state for one connection.
Definition h2_plan.cc:135
Receives bytes after any transport decoding.
Optional observer for application bytes consumed by mock peers.