From 5fa0fc280bcf0e86cf2293ecc8ab17ed99258315 Mon Sep 17 00:00:00 2001 From: Harvey Tuch Date: Thu, 30 Aug 2018 18:33:50 -0400 Subject: [PATCH] fuzz: fix H2 codec fuzzer post #4262. In #4262, an ASSERT was added to guarantee that we wouldn't violate the codec response contract regarding :status. This needed a corresponding change in the H2 codec fuzzer. Risk level: Low Testing: Corpus entry added. Signed-off-by: Harvey Tuch --- ...case-codec_impl_fuzz_test-5750359880892416 | 23 +++++++++++++++++++ .../common/http/http2/codec_impl_fuzz_test.cc | 7 +++++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 test/common/http/http2/codec_impl_corpus/clusterfuzz-testcase-codec_impl_fuzz_test-5750359880892416 diff --git a/test/common/http/http2/codec_impl_corpus/clusterfuzz-testcase-codec_impl_fuzz_test-5750359880892416 b/test/common/http/http2/codec_impl_corpus/clusterfuzz-testcase-codec_impl_fuzz_test-5750359880892416 new file mode 100644 index 000000000000..b9035dc8ee20 --- /dev/null +++ b/test/common/http/http2/codec_impl_corpus/clusterfuzz-testcase-codec_impl_fuzz_test-5750359880892416 @@ -0,0 +1,23 @@ +actions { + new_stream { + } +} +actions { + mutate { + buffer: 2 + offset: 2 + value: 2 + } +} +actions { + client_drain { + } +} +actions { + stream_action { + response { + headers { + } + } + } +} diff --git a/test/common/http/http2/codec_impl_fuzz_test.cc b/test/common/http/http2/codec_impl_fuzz_test.cc index c1845118f50b..b12ff9f253bd 100644 --- a/test/common/http/http2/codec_impl_fuzz_test.cc +++ b/test/common/http/http2/codec_impl_fuzz_test.cc @@ -105,6 +105,7 @@ class Stream : public LinkedObject { void directionalAction(DirectionalState& state, const test::common::http::http2::DirectionalAction& directional_action) { const bool end_stream = directional_action.end_stream(); + const bool response = &state == &response_; switch (directional_action.directional_action_selector_case()) { case test::common::http::http2::DirectionalAction::kContinueHeaders: { if (state.stream_state_ == StreamState::PendingHeaders) { @@ -116,7 +117,11 @@ class Stream : public LinkedObject { } case test::common::http::http2::DirectionalAction::kHeaders: { if (state.stream_state_ == StreamState::PendingHeaders) { - state.encoder_->encodeHeaders(Fuzz::fromHeaders(directional_action.headers()), end_stream); + auto headers = Fuzz::fromHeaders(directional_action.headers()); + if (response && headers.Status() == nullptr) { + headers.setReferenceKey(Headers::get().Status, "200"); + } + state.encoder_->encodeHeaders(headers, end_stream); state.stream_state_ = end_stream ? StreamState::Closed : StreamState::PendingDataOrTrailers; } break;