After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 727944 - crash during Empathy startup: segfault in g_date_time_to_utc from _edsf_persona_update
crash during Empathy startup: segfault in g_date_time_to_utc from _edsf_perso...
Status: RESOLVED FIXED
Product: folks
Classification: Platform
Component: e-d-s backend
0.9.x
Other Linux
: Normal major
: 0.10.x
Assigned To: folks-maint
folks-maint
Depends on:
Blocks:
 
 
Reported: 2014-04-10 09:04 UTC by Simon McVittie
Modified: 2014-04-21 16:42 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
eds: Fix crash on handling invalid birthday dates from contacts (2.02 KB, patch)
2014-04-20 20:14 UTC, Philip Withnall
committed Details | Review
telepathy: Fix crash on handling invalid birthday dates from contacts (3.11 KB, patch)
2014-04-20 20:14 UTC, Philip Withnall
committed Details | Review
tracker: Fix crash on handling invalid birthday dates from contacts (1.42 KB, patch)
2014-04-20 20:14 UTC, Philip Withnall
committed Details | Review
tests: Add assertions to check for null DateTimes (1.88 KB, patch)
2014-04-20 20:14 UTC, Philip Withnall
committed Details | Review

Description Simon McVittie 2014-04-10 09:04:37 UTC
<http://bugs.debian.org/744078> is an Empathy crash. We don't have a detailed backtrace with debug symbols yet, but it's a segfault in g_date_time_to_utc() as called by _edsf_persona_update().

<https://bugs.archlinux.org/task/39200> appears to be the same bug. Again, no debug symbols.

Looking at the source code,


      var d = new DateTime (Persona._local_time_zone,
          (int) bday.year, (int) bday.month, (int) bday.day, 0, 0, 0.0);
      if (this._birthday == null ||
          (this._birthday != null &&
              !((!) this._birthday).equal (d.to_utc ())))
        {
          this._birthday = d.to_utc ();
          this.notify_property ("birthday");
        }

the only way I can see for that to crash is if d was NULL, which
could happen if one of bday.year, bday.month, bday.day is out-of-range. I've asked the bug submitter whether they have any contacts with an impossible birthday like 31st February.

A possible patch:

--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -1176,9 +1176,12 @@ public class Edsf.Persona : Folks.Persona,
            * /etc/localtime, which means lots of syscalls. */
           var d = new DateTime (Persona._local_time_zone,
               (int) bday.year, (int) bday.month, (int) bday.day, 0, 0, 0.0);
-          if (this._birthday == null ||
+
+          /* d might be null if their birthday in e-d-s is something that
+           * doesn't make sense, like 31st February. If so, ignore it. */
+          if (d != null && (this._birthday == null ||
               (this._birthday != null &&
-                  !((!) this._birthday).equal (d.to_utc ())))
+                  !((!) this._birthday).equal (d.to_utc ()))))
             {
               this._birthday = d.to_utc ();
               this.notify_property ("birthday");
Comment 1 Philip Withnall 2014-04-10 23:31:07 UTC
That looks like the right fix, and even if it doesn’t fix this specific bug (although as you say, there doesn’t seem to be any other way that code can crash), it’s the correct thing to do.

Would you mind committing that patch to master, including an update to NEWS please? We also need to fix all other calls to ‘new DateTime()’ and friends to handle null return values correctly.
Comment 2 Philip Withnall 2014-04-20 20:14:06 UTC
Created attachment 274772 [details] [review]
eds: Fix crash on handling invalid birthday dates from contacts

If a GDateTime cannot be constructed due to the requested date being
invalid or out of range, the constructor will return null. The code was
not previously handling this.
Comment 3 Philip Withnall 2014-04-20 20:14:11 UTC
Created attachment 274773 [details] [review]
telepathy: Fix crash on handling invalid birthday dates from contacts

If a GDateTime cannot be constructed due to the requested date being
invalid or out of range, the constructor will return null. The code was
not previously handling this.
Comment 4 Philip Withnall 2014-04-20 20:14:15 UTC
Created attachment 274774 [details] [review]
tracker: Fix crash on handling invalid birthday dates from contacts

If a GDateTime cannot be constructed due to the requested date being
invalid or out of range, the constructor will return null. The code was
not previously handling this.
Comment 5 Philip Withnall 2014-04-20 20:14:20 UTC
Created attachment 274775 [details] [review]
tests: Add assertions to check for null DateTimes

If the DateTime would end up being invalid, construction fails and null
is returned. Gracefully catch that in the unit tests.
Comment 6 Travis Reitter 2014-04-21 15:36:24 UTC
Review of attachment 274772 [details] [review]:

Looks good
Comment 7 Travis Reitter 2014-04-21 15:36:28 UTC
Review of attachment 274773 [details] [review]:

Looks good
Comment 8 Travis Reitter 2014-04-21 15:36:32 UTC
Review of attachment 274774 [details] [review]:

Looks good
Comment 9 Travis Reitter 2014-04-21 15:36:46 UTC
Review of attachment 274775 [details] [review]:

Looks good, just needs an entry in NEWS
Comment 10 Philip Withnall 2014-04-21 16:42:42 UTC
The first patch adds the NEWS entry. All merged to master.

Attachment 274772 [details] pushed as 5e82482 - eds: Fix crash on handling invalid birthday dates from contacts
Attachment 274773 [details] pushed as f3c9b4b - telepathy: Fix crash on handling invalid birthday dates from contacts
Attachment 274774 [details] pushed as 48f5e70 - tracker: Fix crash on handling invalid birthday dates from contacts
Attachment 274775 [details] pushed as 0085cb4 - tests: Add assertions to check for null DateTimes