diff options
author | fanquake <fanquake@gmail.com> | 2023-04-05 11:37:41 +0100 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2023-04-05 11:50:27 +0100 |
commit | 27ad26de2fcaae993aad753545ecd8c881b9155b (patch) | |
tree | cd33ef0702e296868d63264a1674f296b43fab36 | |
parent | 8c3cc4cad3c1554cf718b06e4a605df7ef5574a4 (diff) | |
parent | 73f4eb511cf80cf52b78627347727ca02774b731 (diff) | |
download | bitcoin-27ad26de2fcaae993aad753545ecd8c881b9155b.tar.xz |
Merge bitcoin/bitcoin#27317: log: Check that the timestamp string is non-empty to avoid undefined behavior
73f4eb511cf80cf52b78627347727ca02774b731 Check that the Timestamp String is valid (John Moffett)
Pull request description:
Follow-up to https://github.com/bitcoin/bitcoin/pull/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 73f4eb511cf80cf52b78627347727ca02774b731
stickies-v:
ACK 73f4eb511cf80cf52b78627347727ca02774b731
Tree-SHA512: 089ed639c193deb98870a8385039b31b4baed821ea907937bfc6f65a5b0981bbf8284b2afec81b2d0a922e2340716b48cf55349640eb6b8c311ef7af25abc361
-rw-r--r-- | src/logging.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/logging.cpp b/src/logging.cpp index 6a7991255d..7725fefeb7 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -352,7 +352,7 @@ std::string BCLog::Logger::LogTimestampStr(const std::string& str) const auto now{SystemClock::now()}; const auto now_seconds{std::chrono::time_point_cast<std::chrono::seconds>(now)}; strStamped = FormatISO8601DateTime(TicksSinceEpoch<std::chrono::seconds>(now_seconds)); - if (m_log_time_micros) { + if (m_log_time_micros && !strStamped.empty()) { strStamped.pop_back(); strStamped += strprintf(".%06dZ", Ticks<std::chrono::microseconds>(now - now_seconds)); } |