From 0efd05d9344882e852f2f0250584a260dd7301a5 Mon Sep 17 00:00:00 2001 From: "Billy O'Neal (VC LIBS)" Date: Mon, 8 Apr 2019 19:24:10 -0700 Subject: [PATCH] Paranoia for overflow of sprintf buffer in the year 10000 --- Release/src/utilities/asyncrt_utils.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Release/src/utilities/asyncrt_utils.cpp b/Release/src/utilities/asyncrt_utils.cpp index 986b64bb73..a2fe96b81e 100644 --- a/Release/src/utilities/asyncrt_utils.cpp +++ b/Release/src/utilities/asyncrt_utils.cpp @@ -649,6 +649,10 @@ utility::string_t datetime::to_string(date_format format) const const int64_t input = static_cast(m_interval / _secondTicks); // convert to seconds const int frac_sec = static_cast(m_interval % _secondTicks); const time_t time = static_cast(input - ntToUnixOffsetSeconds); + if (static_cast(time) > 253370764800ull) { + throw std::out_of_range("The requested year exceeds the year 9999."); + } + struct tm t; #ifdef _MSC_VER if (gmtime_s(&t, &time) != 0)