Skip to content

Commit 9c9e9c5

Browse files
committed
logs: reject overflow values in OTEL_BLRP_SCHEDULE_DELAY parsing
1 parent f2dafbf commit 9c9e9c5

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

sdk/src/common/env_variables.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,14 @@ static bool GetTimeoutFromString(const char *input, std::chrono::system_clock::d
9797

9898
for (; *input && std::isdigit(*input); ++input)
9999
{
100-
result = result * 10 + (*input - '0');
100+
auto digit = (*input - '0');
101+
102+
if (result > (std::numeric_limits<decltype(result)>::max() - digit) / 10)
103+
{
104+
// Rejecting overflow as invalid.
105+
return false;
106+
}
107+
result = result * 10 + digit;
101108
}
102109

103110
if (result == 0)

sdk/test/logs/batch_log_record_processor_test.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,7 @@ TEST_F(BatchLogRecordProcessorTest, TestScheduleDelayInvalidEdgeCasesFromEnv)
429429
BatchLogRecordProcessorOptions options;
430430

431431
EXPECT_EQ(options.schedule_delay_millis, std::chrono::milliseconds(1000))
432-
<< "Failed for case: " << tc.description
433-
<< " (value='" << tc.value << "')";
432+
<< "Failed for case: " << tc.description << " (value='" << tc.value << "')";
434433

435434
unsetenv("OTEL_BLRP_SCHEDULE_DELAY");
436435
}

0 commit comments

Comments
 (0)