[folks] telepathy: Fix crash on handling invalid birthday dates from contacts



commit f3c9b4b47d0a36c6ef19ba0534523243a4c38160
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sun Apr 20 21:08:03 2014 +0100

    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.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=727944

 backends/telepathy/lib/tp-zeitgeist.vala           |    4 ++++
 .../telepathy/lib/tpf-persona-store-cache.vala     |    2 ++
 backends/telepathy/lib/tpf-persona.vala            |   10 +++++++---
 3 files changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/backends/telepathy/lib/tp-zeitgeist.vala b/backends/telepathy/lib/tp-zeitgeist.vala
index 65d7509..eaa19f1 100644
--- a/backends/telepathy/lib/tp-zeitgeist.vala
+++ b/backends/telepathy/lib/tp-zeitgeist.vala
@@ -179,6 +179,10 @@ public class FolksTpZeitgeist.Controller : Object
       var converted_datetime = new DateTime.from_unix_utc (timestamp);
       var interpretation = event.interpretation;
 
+      /* Invalid timestamp? Ignore it. */
+      if (converted_datetime == null)
+          return;
+
       /* Only count send/receive for IM interactions */
       if (interaction_type == Zeitgeist.NMO.IMMESSAGE &&
           (interpretation == Zeitgeist.ZG.SEND_EVENT ||
diff --git a/backends/telepathy/lib/tpf-persona-store-cache.vala 
b/backends/telepathy/lib/tpf-persona-store-cache.vala
index d8d0a63..26296d0 100644
--- a/backends/telepathy/lib/tpf-persona-store-cache.vala
+++ b/backends/telepathy/lib/tpf-persona-store-cache.vala
@@ -305,6 +305,8 @@ internal class Tpf.PersonaStoreCache : Folks.ObjectCache<Tpf.Persona>
           var birthday_variant = variant.get_child_value (10).get_maybe ();
           if (birthday_variant != null)
             {
+              /* Note: This may return a null value if the stored value is
+               * invalid (e.g. out of range). */
               birthday =
                   new DateTime.from_unix_utc (birthday_variant.get_int64 ());
             }
diff --git a/backends/telepathy/lib/tpf-persona.vala b/backends/telepathy/lib/tpf-persona.vala
index 8830158..f336877 100644
--- a/backends/telepathy/lib/tpf-persona.vala
+++ b/backends/telepathy/lib/tpf-persona.vala
@@ -1036,9 +1036,13 @@ public class Tpf.Persona : Folks.Persona,
           if (timeval.from_iso8601 (new_birthday_str))
             {
               var d = new DateTime.from_timeval_utc (timeval);
-              if (this._birthday == null ||
-                  (this._birthday != null &&
-                    !this._birthday.equal (d.to_utc ())))
+
+              /* d might be null if their birthday in Telepathy 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 = d.to_utc ();
                   if (emit_notification)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]