r22171 - gnucash/trunk/src/engine - [Bug 674862] Gnucash crashes after creating a new SX using the Mortgage

John Ralls jralls at code.gnucash.org
Mon May 7 18:54:57 EDT 2012


Author: jralls
Date: 2012-05-07 18:54:56 -0400 (Mon, 07 May 2012)
New Revision: 22171
Trac: http://svn.gnucash.org/trac/changeset/22171

Modified:
   gnucash/trunk/src/engine/SchedXaction.c
Log:
[Bug 674862] Gnucash crashes after creating a new SX using the Mortgage
Wizard and SQL Backend

This addresses the crash reported on Ubuntu with Postgres by Krzysiek.
The stack trace he posted showed the crash was the result of
dereferencing a NULL GDate*, and this change protects against that. It
still doesn't address the more basic problem of why on Win32 and with
mysql and pgsql (but not SQLite3) the mortgage wizard is writing corrupt
dates.

[BP]

Modified: gnucash/trunk/src/engine/SchedXaction.c
===================================================================
--- gnucash/trunk/src/engine/SchedXaction.c	2012-05-06 21:19:34 UTC (rev 22170)
+++ gnucash/trunk/src/engine/SchedXaction.c	2012-05-07 22:54:56 UTC (rev 22171)
@@ -577,12 +577,23 @@
 const GDate*
 xaccSchedXactionGetStartDate(const SchedXaction *sx )
 {
+    g_assert (sx);
     return &sx->start_date;
 }
 
 void
 xaccSchedXactionSetStartDate( SchedXaction *sx, const GDate* newStart )
 {
+    if ( newStart == NULL || !g_date_valid( newStart ))
+    {
+        /* XXX: I reject the bad data - is this the right
+         * thing to do <rgmerk>.
+         * This warning is only human readable - the caller
+         * doesn't know the call failed.  This is bad
+         */
+        g_critical("Invalid Start Date");
+        return;
+    }
     gnc_sx_begin_edit(sx);
     sx->start_date = *newStart;
     qof_instance_set_dirty(&sx->inst);
@@ -592,27 +603,29 @@
 gboolean
 xaccSchedXactionHasEndDate( const SchedXaction *sx )
 {
-    return g_date_valid( &sx->end_date );
+    return sx != NULL && g_date_valid( &sx->end_date );
 }
 
 const GDate*
 xaccSchedXactionGetEndDate(const SchedXaction *sx )
 {
+    g_assert (sx);
     return &sx->end_date;
 }
 
 void
 xaccSchedXactionSetEndDate( SchedXaction *sx, const GDate *newEnd )
 {
-    if ( g_date_valid( newEnd )
-            && g_date_compare( newEnd, &sx->start_date ) < 0 )
+    if (newEnd == NULL
+	|| !g_date_valid( newEnd )
+	|| g_date_compare( newEnd, &sx->start_date ) < 0 )
     {
         /* XXX: I reject the bad data - is this the right
          * thing to do <rgmerk>.
          * This warning is only human readable - the caller
          * doesn't know the call failed.  This is bad
          */
-        g_critical("New end date before start date");
+        g_critical("Bad End Date: Invalid or before Start Date");
         return;
     }
 



More information about the gnucash-changes mailing list