From c4dade7f066156cd676d98e10323fa19de2e85e5 Mon Sep 17 00:00:00 2001 From: Anirudh M Date: Thu, 19 Jul 2018 17:35:23 +0000 Subject: [PATCH 1/4] fuzz: fixes oss-fuzz: 8363 Signed-off-by: Anirudh M --- source/common/protobuf/utility.h | 2 +- ...testcase-server_fuzz_test-5988544525893632 | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 test/server/server_corpus/clusterfuzz-testcase-server_fuzz_test-5988544525893632 diff --git a/source/common/protobuf/utility.h b/source/common/protobuf/utility.h index 787dfed1b228..64e9e0a366dd 100644 --- a/source/common/protobuf/utility.h +++ b/source/common/protobuf/utility.h @@ -65,7 +65,7 @@ uint64_t fractionalPercentDenominatorToInt(const envoy::type::FractionalPercent& // @param default_value supplies the default if the field is not present. #define PROTOBUF_PERCENT_TO_ROUNDED_INTEGER_OR_DEFAULT(message, field_name, max_value, \ default_value) \ - ((message).has_##field_name() \ + ((message).has_##field_name() && !std::isnan((message).field_name().value()) \ ? ProtobufPercentHelper::convertPercent((message).field_name().value(), max_value) \ : ProtobufPercentHelper::checkAndReturnDefault(default_value, max_value)) diff --git a/test/server/server_corpus/clusterfuzz-testcase-server_fuzz_test-5988544525893632 b/test/server/server_corpus/clusterfuzz-testcase-server_fuzz_test-5988544525893632 new file mode 100644 index 000000000000..5c8b2ec2c49e --- /dev/null +++ b/test/server/server_corpus/clusterfuzz-testcase-server_fuzz_test-5988544525893632 @@ -0,0 +1,29 @@ +static_resources { + clusters { + name: "-2353373969551157135775236" + connect_timeout { + seconds: 12884901890 + } + hosts { + pipe { + path: "@" + } + } + outlier_detection { + } + common_lb_config { + healthy_panic_threshold { + value: nan + } + } + } +} +admin { + access_log_path: "@r" + address { + pipe { + path: "W" + } + } +} + From 4b80067ad2d23658338031aec62ecf4a702020e1 Mon Sep 17 00:00:00 2001 From: Anirudh M Date: Mon, 23 Jul 2018 20:09:48 +0000 Subject: [PATCH 2/4] added todo Signed-off-by: Anirudh M --- source/common/protobuf/utility.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/common/protobuf/utility.h b/source/common/protobuf/utility.h index 64e9e0a366dd..acde9408e186 100644 --- a/source/common/protobuf/utility.h +++ b/source/common/protobuf/utility.h @@ -63,6 +63,9 @@ uint64_t fractionalPercentDenominatorToInt(const envoy::type::FractionalPercent& // @param field_name supplies the field name in the message. // @param max_value supplies the maximum allowed integral value (e.g., 100, 10000, etc.). // @param default_value supplies the default if the field is not present. +// +// TODO(anirudhmurali): Recommended to capture and validate NaN values in PGV +// Issue: https://github.com/lyft/protoc-gen-validate/issues/85 #define PROTOBUF_PERCENT_TO_ROUNDED_INTEGER_OR_DEFAULT(message, field_name, max_value, \ default_value) \ ((message).has_##field_name() && !std::isnan((message).field_name().value()) \ From 90e3738a97edc408623a6dc9761babdc6472cdcc Mon Sep 17 00:00:00 2001 From: Anirudh M Date: Tue, 24 Jul 2018 15:40:09 +0000 Subject: [PATCH 3/4] addressed comments Signed-off-by: Anirudh M --- source/common/protobuf/utility.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/common/protobuf/utility.h b/source/common/protobuf/utility.h index acde9408e186..f1f27271a4d6 100644 --- a/source/common/protobuf/utility.h +++ b/source/common/protobuf/utility.h @@ -68,8 +68,10 @@ uint64_t fractionalPercentDenominatorToInt(const envoy::type::FractionalPercent& // Issue: https://github.com/lyft/protoc-gen-validate/issues/85 #define PROTOBUF_PERCENT_TO_ROUNDED_INTEGER_OR_DEFAULT(message, field_name, max_value, \ default_value) \ - ((message).has_##field_name() && !std::isnan((message).field_name().value()) \ - ? ProtobufPercentHelper::convertPercent((message).field_name().value(), max_value) \ + ((message).has_##field_name() \ + ? !std::isnan((message).field_name().value()) \ + ? ProtobufPercentHelper::convertPercent((message).field_name().value(), max_value) \ + : throw EnvoyException(fmt::format("Value not in the range of 0..100 range.")) \ : ProtobufPercentHelper::checkAndReturnDefault(default_value, max_value)) namespace Envoy { From 6b9cb71a991a7fcea94e703730129e7f42fd6ac9 Mon Sep 17 00:00:00 2001 From: Anirudh M Date: Wed, 25 Jul 2018 16:29:16 +0000 Subject: [PATCH 4/4] added tests and addressed comments Signed-off-by: Anirudh M --- source/common/protobuf/utility.h | 8 ++++---- test/common/protobuf/utility_test.cc | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/source/common/protobuf/utility.h b/source/common/protobuf/utility.h index f1f27271a4d6..e6448f9aff67 100644 --- a/source/common/protobuf/utility.h +++ b/source/common/protobuf/utility.h @@ -68,11 +68,11 @@ uint64_t fractionalPercentDenominatorToInt(const envoy::type::FractionalPercent& // Issue: https://github.com/lyft/protoc-gen-validate/issues/85 #define PROTOBUF_PERCENT_TO_ROUNDED_INTEGER_OR_DEFAULT(message, field_name, max_value, \ default_value) \ - ((message).has_##field_name() \ - ? !std::isnan((message).field_name().value()) \ + (!std::isnan((message).field_name().value()) \ + ? (message).has_##field_name() \ ? ProtobufPercentHelper::convertPercent((message).field_name().value(), max_value) \ - : throw EnvoyException(fmt::format("Value not in the range of 0..100 range.")) \ - : ProtobufPercentHelper::checkAndReturnDefault(default_value, max_value)) + : ProtobufPercentHelper::checkAndReturnDefault(default_value, max_value) \ + : throw EnvoyException(fmt::format("Value not in the range of 0..100 range."))) namespace Envoy { diff --git a/test/common/protobuf/utility_test.cc b/test/common/protobuf/utility_test.cc index 9351f9a25763..298b853a2042 100644 --- a/test/common/protobuf/utility_test.cc +++ b/test/common/protobuf/utility_test.cc @@ -13,6 +13,15 @@ namespace Envoy { +TEST(UtilityTest, convertPercentNaN) { + envoy::api::v2::Cluster::CommonLbConfig common_config_; + common_config_.mutable_healthy_panic_threshold()->set_value( + std::numeric_limits::quiet_NaN()); + EXPECT_THROW(PROTOBUF_PERCENT_TO_ROUNDED_INTEGER_OR_DEFAULT(common_config_, + healthy_panic_threshold, 100, 50), + EnvoyException); +} + TEST(UtilityTest, RepeatedPtrUtilDebugString) { Protobuf::RepeatedPtrField repeated; EXPECT_EQ("[]", RepeatedPtrUtil::debugString(repeated));