Skip to content

Commit 12cc3b7

Browse files
committed
Guard against large float values
1 parent d711cf0 commit 12cc3b7

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

exporters/otlp/src/otlp_grpc_client.cc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,9 @@ std::shared_ptr<grpc::Channel> OtlpGrpcClient::MakeChannel(const OtlpGrpcClientO
362362
"name": [{}],
363363
"retryPolicy": {
364364
"maxAttempts": %0000000000u,
365-
"initialBackoff": "%.1fs",
366-
"maxBackoff": "%.1fs",
367-
"backoffMultiplier": %.1f,
365+
"initialBackoff": "%0000000000.1fs",
366+
"maxBackoff": "%0000000000.1fs",
367+
"backoffMultiplier": %0000000000.1f,
368368
"retryableStatusCodes": [
369369
"CANCELLED",
370370
"DEADLINE_EXCEEDED",
@@ -381,11 +381,12 @@ std::shared_ptr<grpc::Channel> OtlpGrpcClient::MakeChannel(const OtlpGrpcClientO
381381
// Allocate string with buffer large enough to hold the formatted json config
382382
auto service_config = std::string(kServiceConfigJson.size(), '\0');
383383
// Prior to C++17, need to explicitly cast away constness from `data()` buffer
384-
std::snprintf(const_cast<decltype(service_config)::value_type *>(service_config.data()),
385-
service_config.size(), kServiceConfigJson.data(),
386-
options.retry_policy_max_attempts, options.retry_policy_initial_backoff.count(),
387-
options.retry_policy_max_backoff.count(),
388-
options.retry_policy_backoff_multiplier);
384+
std::snprintf(
385+
const_cast<decltype(service_config)::value_type *>(service_config.data()),
386+
service_config.size(), kServiceConfigJson.data(), options.retry_policy_max_attempts,
387+
std::min(std::max(options.retry_policy_initial_backoff.count(), 0.f), 999999999.f),
388+
std::min(std::max(options.retry_policy_max_backoff.count(), 0.f), 999999999.f),
389+
std::min(std::max(options.retry_policy_backoff_multiplier, 0.f), 999999999.f));
389390

390391
grpc_arguments.SetServiceConfigJSON(service_config);
391392
}

0 commit comments

Comments
 (0)