Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fuzz: fixes oss-fuzz: 8363 #3905

Merged
merged 4 commits into from
Jul 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions source/common/protobuf/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,16 @@ 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() \
? ProtobufPercentHelper::convertPercent((message).field_name().value(), max_value) \
: ProtobufPercentHelper::checkAndReturnDefault(default_value, max_value))
(!std::isnan((message).field_name().value()) \
? (message).has_##field_name() \
? ProtobufPercentHelper::convertPercent((message).field_name().value(), max_value) \
: ProtobufPercentHelper::checkAndReturnDefault(default_value, max_value) \
: throw EnvoyException(fmt::format("Value not in the range of 0..100 range.")))

namespace Envoy {

Expand Down
9 changes: 9 additions & 0 deletions test/common/protobuf/utility_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>::quiet_NaN());
EXPECT_THROW(PROTOBUF_PERCENT_TO_ROUNDED_INTEGER_OR_DEFAULT(common_config_,
healthy_panic_threshold, 100, 50),
EnvoyException);
}

TEST(UtilityTest, RepeatedPtrUtilDebugString) {
Protobuf::RepeatedPtrField<ProtobufWkt::UInt32Value> repeated;
EXPECT_EQ("[]", RepeatedPtrUtil::debugString(repeated));
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
}
}