util: Avoid potential uninitialized read in FormatISO8601DateTime(int64_t nTime) by checking gmtime_s/gmtime_r return value
This commit is contained in:
parent
eddcbfb109
commit
12a2f37718
|
@ -12,7 +12,7 @@ export NO_DEPENDS=1
|
||||||
export RUN_UNIT_TESTS=false
|
export RUN_UNIT_TESTS=false
|
||||||
export RUN_FUNCTIONAL_TESTS=false
|
export RUN_FUNCTIONAL_TESTS=false
|
||||||
export RUN_FUZZ_TESTS=true
|
export RUN_FUZZ_TESTS=true
|
||||||
export FUZZ_TESTS_CONFIG="--exclude integer,parse_iso8601 --valgrind"
|
export FUZZ_TESTS_CONFIG="--valgrind"
|
||||||
export GOAL="install"
|
export GOAL="install"
|
||||||
export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer CC=clang-8 CXX=clang++-8"
|
export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer CC=clang-8 CXX=clang++-8"
|
||||||
# Use clang-8, instead of default clang on bionic, which is clang-6 and does not come with libfuzzer on aarch64
|
# Use clang-8, instead of default clang on bionic, which is clang-6 and does not come with libfuzzer on aarch64
|
||||||
|
|
|
@ -94,10 +94,12 @@ std::string FormatISO8601DateTime(int64_t nTime) {
|
||||||
struct tm ts;
|
struct tm ts;
|
||||||
time_t time_val = nTime;
|
time_t time_val = nTime;
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
gmtime_s(&ts, &time_val);
|
if (gmtime_s(&ts, &time_val) != 0) {
|
||||||
#else
|
#else
|
||||||
gmtime_r(&time_val, &ts);
|
if (gmtime_r(&time_val, &ts) == nullptr) {
|
||||||
#endif
|
#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);
|
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;
|
struct tm ts;
|
||||||
time_t time_val = nTime;
|
time_t time_val = nTime;
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
gmtime_s(&ts, &time_val);
|
if (gmtime_s(&ts, &time_val) != 0) {
|
||||||
#else
|
#else
|
||||||
gmtime_r(&time_val, &ts);
|
if (gmtime_r(&time_val, &ts) == nullptr) {
|
||||||
#endif
|
#endif
|
||||||
|
return {};
|
||||||
|
}
|
||||||
return strprintf("%04i-%02i-%02i", ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday);
|
return strprintf("%04i-%02i-%02i", ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue