Skip to content

Commit 27ad26d

Browse files
committed
Merge bitcoin/bitcoin#27317: log: Check that the timestamp string is non-empty to avoid undefined behavior
73f4eb5 Check that the Timestamp String is valid (John Moffett) Pull request description: Follow-up to bitcoin/bitcoin#27233 The current `FormatISO8601DateTime` function will return an empty string if it encounters an error when converting the `int64_t` seconds-since-epoch to a formatted date time. In the unlikely case that happens, here `strStamped.pop_back()` would be undefined behavior. ACKs for top commit: MarcoFalke: lgtm ACK 73f4eb5 stickies-v: ACK 73f4eb5 Tree-SHA512: 089ed639c193deb98870a8385039b31b4baed821ea907937bfc6f65a5b0981bbf8284b2afec81b2d0a922e2340716b48cf55349640eb6b8c311ef7af25abc361
2 parents 8c3cc4c + 73f4eb5 commit 27ad26d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/logging.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ std::string BCLog::Logger::LogTimestampStr(const std::string& str)
352352
const auto now{SystemClock::now()};
353353
const auto now_seconds{std::chrono::time_point_cast<std::chrono::seconds>(now)};
354354
strStamped = FormatISO8601DateTime(TicksSinceEpoch<std::chrono::seconds>(now_seconds));
355-
if (m_log_time_micros) {
355+
if (m_log_time_micros && !strStamped.empty()) {
356356
strStamped.pop_back();
357357
strStamped += strprintf(".%06dZ", Ticks<std::chrono::microseconds>(now - now_seconds));
358358
}

0 commit comments

Comments
 (0)