From 1b3cbb27ad56c38903210eb6a860375c532b93de Mon Sep 17 00:00:00 2001 From: Harvey Tuch Date: Sat, 25 Aug 2018 22:28:52 -0400 Subject: [PATCH 1/4] fuzz: use nanoseconds for SystemTime in RequestInfo. Avoids integer overflow that was previously occurring due to time in micros being too large, allows exercise of nanosecond resolution formatters beyond all zero. Fixes oss-fuzz issue https://oss-fuzz.com/v2/testcase-detail/5630125928873984. Risk level: Low Testing: Corpus entry added. Signed-off-by: Harvey Tuch --- ...-testcase-minimized-header_parser_fuzz_test-5630125928873984 | 1 + test/fuzz/utility.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 test/common/router/header_parser_corpus/clusterfuzz-testcase-minimized-header_parser_fuzz_test-5630125928873984 diff --git a/test/common/router/header_parser_corpus/clusterfuzz-testcase-minimized-header_parser_fuzz_test-5630125928873984 b/test/common/router/header_parser_corpus/clusterfuzz-testcase-minimized-header_parser_fuzz_test-5630125928873984 new file mode 100644 index 000000000000..51cef79477d3 --- /dev/null +++ b/test/common/router/header_parser_corpus/clusterfuzz-testcase-minimized-header_parser_fuzz_test-5630125928873984 @@ -0,0 +1 @@ +headers_to_add { header { key: " " value: "%START_TIME(�)%" } } request_info { start_time: 72059116831228591 } diff --git a/test/fuzz/utility.h b/test/fuzz/utility.h index 4536ae49bb08..b389ec7b7040 100644 --- a/test/fuzz/utility.h +++ b/test/fuzz/utility.h @@ -36,7 +36,7 @@ inline test::fuzz::Headers toHeaders(const Http::HeaderMap& headers) { inline TestRequestInfo fromRequestInfo(const test::fuzz::RequestInfo& request_info) { TestRequestInfo test_request_info; test_request_info.metadata_ = request_info.dynamic_metadata(); - test_request_info.start_time_ = SystemTime(std::chrono::microseconds(request_info.start_time())); + test_request_info.start_time_ = SystemTime(std::chrono::nanoseconds(request_info.start_time())); if (request_info.has_response_code()) { test_request_info.response_code_ = request_info.response_code().value(); } From 1c691f4788b1ad174ab5b01531430171fc9ec5e5 Mon Sep 17 00:00:00 2001 From: Harvey Tuch Date: Sun, 26 Aug 2018 10:47:57 -0400 Subject: [PATCH 2/4] Make *Time explicitly nanoseconds duration for OS X. Signed-off-by: Harvey Tuch --- include/envoy/common/time.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/envoy/common/time.h b/include/envoy/common/time.h index 6fd7e6e7198b..9168aedfdb0e 100644 --- a/include/envoy/common/time.h +++ b/include/envoy/common/time.h @@ -11,8 +11,8 @@ namespace Envoy { * SystemTime should be used when getting a time to present to the user, e.g. for logging. * MonotonicTime should be used when tracking time for computing an interval. */ -typedef std::chrono::time_point SystemTime; -typedef std::chrono::time_point MonotonicTime; +typedef std::chrono::time_point SystemTime; +typedef std::chrono::time_point MonotonicTime; /** * Abstraction for getting the current system time. Useful for testing. From 8efc740006fc952a182b36db5f03c1b36c25f221 Mon Sep 17 00:00:00 2001 From: Harvey Tuch Date: Sun, 26 Aug 2018 12:19:09 -0400 Subject: [PATCH 3/4] Revert "Make *Time explicitly nanoseconds duration for OS X." This reverts commit 1c691f4788b1ad174ab5b01531430171fc9ec5e5. Signed-off-by: Harvey Tuch --- include/envoy/common/time.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/envoy/common/time.h b/include/envoy/common/time.h index 9168aedfdb0e..6fd7e6e7198b 100644 --- a/include/envoy/common/time.h +++ b/include/envoy/common/time.h @@ -11,8 +11,8 @@ namespace Envoy { * SystemTime should be used when getting a time to present to the user, e.g. for logging. * MonotonicTime should be used when tracking time for computing an interval. */ -typedef std::chrono::time_point SystemTime; -typedef std::chrono::time_point MonotonicTime; +typedef std::chrono::time_point SystemTime; +typedef std::chrono::time_point MonotonicTime; /** * Abstraction for getting the current system time. Useful for testing. From aedc2a247881bc4cb590a96aeb5b13249466d3e1 Mon Sep 17 00:00:00 2001 From: Harvey Tuch Date: Sun, 26 Aug 2018 12:24:49 -0400 Subject: [PATCH 4/4] Workaround for OS X micros resolution clock. Signed-off-by: Harvey Tuch --- test/fuzz/utility.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/fuzz/utility.h b/test/fuzz/utility.h index b389ec7b7040..f50659e0c3f2 100644 --- a/test/fuzz/utility.h +++ b/test/fuzz/utility.h @@ -36,7 +36,13 @@ inline test::fuzz::Headers toHeaders(const Http::HeaderMap& headers) { inline TestRequestInfo fromRequestInfo(const test::fuzz::RequestInfo& request_info) { TestRequestInfo test_request_info; test_request_info.metadata_ = request_info.dynamic_metadata(); +#ifdef __APPLE__ + // Clocks don't track at nanosecond on OS X. + test_request_info.start_time_ = + SystemTime(std::chrono::microseconds(request_info.start_time() / 1000)); +#else test_request_info.start_time_ = SystemTime(std::chrono::nanoseconds(request_info.start_time())); +#endif if (request_info.has_response_code()) { test_request_info.response_code_ = request_info.response_code().value(); }