Skip to content

Conversation

anirudhmurali
Copy link
Member

Title: Fixes oss-fuzz: 9895

Description: oss-fuzz issue (9895): https://oss-fuzz.com/v2/testcase-detail/6195059702628352
The given input testcase had multiple START_TIME formatters as value, a valid input must contain only one START_TIME, throwing exception if invalid.

Risk Level: Low

Testing: Tested unit tests (bazel test //test/common/router:header_parser_fuzz_test), built and ran fuzzers with oss-fuzz.

Signed-off-by: Anirudh M m.anirudh18@gmail.com

Signed-off-by: Anirudh M <m.anirudh18@gmail.com>
Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this one on.

@@ -143,7 +143,10 @@ RequestInfoHeaderFormatter::RequestInfoHeaderFormatter(absl::string_view field_n
}
field_extractor_ = [this, pattern](const Envoy::RequestInfo::RequestInfo& request_info) {
const auto& formatters = start_time_formatters_.at(pattern);
ASSERT(formatters.size() == 1);
if (formatters.size() != 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dio does this seem right?

Copy link
Member

@dio dio Aug 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think yes. From the current use-case perspective, this is correct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the second thought, I think we can support multiple patterns.

@anirudhmurali Do you want to take it?

@@ -0,0 +1,8 @@
headers_to_add {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anirudhmurali can you add a test case to the unit tests for header_formatter.cc? Best practice is to check in both corpus and a unit test for the new error handling.

@htuch htuch assigned dio and htuch Aug 16, 2018
@htuch htuch requested a review from dio August 16, 2018 20:40
ASSERT(formatters.size() == 1);
if (formatters.size() != 1) {
throw EnvoyException(
fmt::format("multiple start_time values found: {}", formatters.size()));
Copy link
Member

@dio dio Aug 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anirudhmurali, thanks for checking on this.

Questions:

1. Do you think "multiple %START_TIME% patterns..." sounds better?
2. Is the input here: https://github.com/envoyproxy/envoy/pull/4189/files#diff-084669b1d67ce3df5fbda83bef9354bbR3 causing this?

Copy link
Member

@dio dio Aug 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NVM, I tried to patch the header_formatter to accept this pattern from the corpus, and it seems it makes sense to have multiple patterns inline as the header value.

@anirudhmurali, as I said above, I can work with you to fix this.

(This fuzzer is really good then. This is my mistake, sorry).

Signed-off-by: Anirudh M <m.anirudh18@gmail.com>
@anirudhmurali
Copy link
Member Author

@dio With regards to the Slack discussion and the GitHub comments, I believe this allows definition of multiple START_TIME patterns. Have added the case to the test file as well. Please let me know if there is anything more to this. Thanks.

Signed-off-by: Anirudh M <m.anirudh18@gmail.com>
Copy link
Member

@dio dio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @anirudhmurali! Looks good. One small request.

@@ -617,6 +617,10 @@ match: { prefix: "/new_endpoint" }
key: "x-request-start"
value: "%START_TIME(%s.%3f)%"
append: true
- header:
key: "x-request-start"
Copy link
Member

@dio dio Aug 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename the key to something else, e.g. "x-request-start-multiple", and add some similar expectations below.

EXPECT_TRUE(headerMap.has("x-request-start-multiple"));
EXPECT_EQ("1522796769.123 2018-04-03T23:06:09.123Z 1522796769", headerMap.get_("x-request-start-multiple"));

Signed-off-by: Anirudh M <m.anirudh18@gmail.com>
Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; @dio do you want to take a final pass and merge if it look good to you?

Copy link
Member

@dio dio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks, @anirudhmurali!

@htuch sure! Will do that soon after the CI is done the checking. Thank you!

@htuch htuch merged commit db4783b into envoyproxy:master Aug 20, 2018
snowp pushed a commit to snowp/envoy that referenced this pull request Aug 20, 2018
* origin/master: (34 commits)
  fuzz: fixes oss-fuzz: 9895 (envoyproxy#4189)
  docs: added developer docs for pprof/tcmalloc testing (envoyproxy#4194)
  fix sometimes returns response body to HEAD requests (envoyproxy#3985)
  admin: fix config dump order (envoyproxy#4197)
  thrift: allow translation between downstream and upstream protocols (envoyproxy#4136)
  Use local_info.node() instead of bootstrap.node() whenever possible (envoyproxy#4120)
  upstream: allow extension protocol options to be used with http filters (envoyproxy#4165)
  [thrift_proxy] Replace local HeaderMap with Http::HeaderMap[Impl] (envoyproxy#4169)
  docs: improve gRPC-JSON filter doc (envoyproxy#4184)
  stats: refactoring MetricImpl without strings (envoyproxy#4190)
  fuzz: coverage profile generation instructions. (envoyproxy#4193)
  upstream: rebuild cluster when health check config is changed (envoyproxy#4075)
  build: use clang-6.0. (envoyproxy#4168)
  thrift_proxy: introduce header transport (envoyproxy#4082)
  tcp: allow connection pool callers to store protocol state (envoyproxy#4131)
  configs: match latest API changes (envoyproxy#4185)
  Fix wrong mock function name. (envoyproxy#4187)
  Bump yaml-cpp so it builds with Visual Studio 15.8 (envoyproxy#4182)
  Converting envoy configs to V2 (envoyproxy#2957)
  Add timestamp to HealthCheckEvent definition (envoyproxy#4119)
  ...

Signed-off-by: Snow Pettersen <snowp@squareup.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants