gnucash maint: Bug 798199 - Pasting invalid value in date column crashes GnuCash

John Ralls jralls at code.gnucash.org
Tue Jun 8 16:16:39 EDT 2021


Updated	 via  https://github.com/Gnucash/gnucash/commit/42213c59 (commit)
	from  https://github.com/Gnucash/gnucash/commit/66685f04 (commit)



commit 42213c597ca5214b97f2919f573fbfdaad4a8219
Author: John Ralls <jralls at ceridwen.us>
Date:   Tue Jun 8 13:14:30 2021 -0700

    Bug 798199 - Pasting invalid value in date column crashes GnuCash
    
    Catch boost::gregorian::bad_year in LDT_from_struct_tm and rethrow
    std::invalid_argument for C wrappers to catch and handle.

diff --git a/libgnucash/engine/gnc-datetime.cpp b/libgnucash/engine/gnc-datetime.cpp
index 9563393e8..ea1df6018 100644
--- a/libgnucash/engine/gnc-datetime.cpp
+++ b/libgnucash/engine/gnc-datetime.cpp
@@ -255,11 +255,18 @@ LDT_from_date_daypart(const Date& date, DayPart part, const TZ_Ptr tz)
 static LDT
 LDT_from_struct_tm(const struct tm tm)
 {
-    Date tdate{boost::gregorian::date_from_tm(tm)};
-    Duration tdur{boost::posix_time::time_duration(tm.tm_hour, tm.tm_min,
-                                                  tm.tm_sec, 0)};
-    TZ_Ptr tz{tzp->get(tdate.year())};
-    return LDT_from_date_time(tdate, tdur, tz);
+    try
+    {
+        Date tdate{boost::gregorian::date_from_tm(tm)};
+        Duration tdur{boost::posix_time::time_duration(tm.tm_hour, tm.tm_min,
+                                                       tm.tm_sec, 0)};
+        TZ_Ptr tz{tzp->get(tdate.year())};
+        return LDT_from_date_time(tdate, tdur, tz);
+    }
+    catch(const boost::gregorian::bad_year&)
+    {
+        throw(std::invalid_argument{"Time value is outside the supported year range."});
+    }
 }
 
 void



Summary of changes:
 libgnucash/engine/gnc-datetime.cpp | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)



More information about the gnucash-changes mailing list