aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorpracticalswift <practicalswift@users.noreply.github.com>2020-02-16 11:28:37 +0000
committerpracticalswift <practicalswift@users.noreply.github.com>2020-02-19 22:41:06 +0000
commit12a2f377185a413b740460db36812de22ee2e041 (patch)
treef1eec49f16605e5cd0843278187578d087d7fb8f /src/util
parenteddcbfb109e592fdf39ea2c38c4d7ba183de3e34 (diff)
downloadbitcoin-12a2f377185a413b740460db36812de22ee2e041.tar.xz
util: Avoid potential uninitialized read in FormatISO8601DateTime(int64_t nTime) by checking gmtime_s/gmtime_r return value
Diffstat (limited to 'src/util')
-rw-r--r--src/util/time.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/util/time.cpp b/src/util/time.cpp
index 2afff2626b..f33966f149 100644
--- a/src/util/time.cpp
+++ b/src/util/time.cpp
@@ -94,10 +94,12 @@ std::string FormatISO8601DateTime(int64_t nTime) {
struct tm ts;
time_t time_val = nTime;
#ifdef _MSC_VER
- gmtime_s(&ts, &time_val);
+ if (gmtime_s(&ts, &time_val) != 0) {
#else
- gmtime_r(&time_val, &ts);
+ if (gmtime_r(&time_val, &ts) == nullptr) {
#endif
+ return {};
+ }
return strprintf("%04i-%02i-%02iT%02i:%02i:%02iZ", ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec);
}
@@ -105,10 +107,12 @@ std::string FormatISO8601Date(int64_t nTime) {
struct tm ts;
time_t time_val = nTime;
#ifdef _MSC_VER
- gmtime_s(&ts, &time_val);
+ if (gmtime_s(&ts, &time_val) != 0) {
#else
- gmtime_r(&time_val, &ts);
+ if (gmtime_r(&time_val, &ts) == nullptr) {
#endif
+ return {};
+ }
return strprintf("%04i-%02i-%02i", ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday);
}
@@ -124,4 +128,4 @@ int64_t ParseISO8601DateTime(const std::string& str)
if (ptime.is_not_a_date_time() || epoch > ptime)
return 0;
return (ptime - epoch).total_seconds();
-} \ No newline at end of file
+}