[folks] backends: Work around a Vala const-array null-termination bug



commit 20622279cb5cfef2b3201a7e122321377a1fc96a
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Tue Oct 8 15:06:13 2013 +0100

    backends: Work around a Vala const-array null-termination bug
    
    Bug #682698 means that Vala does not null-terminate const arrays, yet it
    expects them to be null terminated when returning them to g_object_get().
    This results in g_object_get() walking off into arbitrary memory, and Bad
    Things happen shortly afterwards.
    
    Work around this (because it doesn’t look like the Vala bug is going to be
    fixed any time soon) by manually null-terminating all const arrays (typically
    linkable_properties and writeable_properties lists in backends) and modifying
    code which iterates over them to ignore null entries.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=682698

 NEWS                                        |    2 ++
 backends/eds/lib/edsf-persona.vala          |   12 ++++++++----
 backends/key-file/kf-persona-store.vala     |    3 ++-
 backends/key-file/kf-persona.vala           |    6 ++++--
 backends/libsocialweb/lib/swf-persona.vala  |    3 ++-
 backends/ofono/ofono-persona.vala           |    3 ++-
 backends/telepathy/lib/tpf-persona.vala     |    6 +++++-
 backends/tracker/lib/trf-persona-store.vala |    3 ++-
 backends/tracker/lib/trf-persona.vala       |   10 ++++++++--
 folks/individual-aggregator.vala            |   16 ++++++++++++++++
 10 files changed, 51 insertions(+), 13 deletions(-)
---
diff --git a/NEWS b/NEWS
index 6ec3551..00fdcc9 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,8 @@ Bugs fixed:
 • Bug 709674 — Ignore non-phonebook-enabled modems in ofono backend
 • Bug 697209 — Individual: connect to Persona::notify less enthusiastically
 • Bug 710178 — Skip whitespace between oFono vCards
+• Bug 682698 — const string[] not NULL terminated; crashes in GBoxed property
+  getter (workaround)
 
 API changes:
 
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index 55d77ae..0274605 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -147,10 +147,14 @@ public class Edsf.Persona : Folks.Persona,
    */
   public static const string gender_female = "F";
 
-  private const string[] _linkable_properties = { "im-addresses",
-                                                  "email-addresses",
-                                                  "local-ids",
-                                                  "web-service-addresses" };
+  private const string[] _linkable_properties =
+    {
+      "im-addresses",
+      "email-addresses",
+      "local-ids",
+      "web-service-addresses",
+      null /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=682698 */
+    };
 
   private static GLib.HashTable<string, E.ContactField>? _im_eds_map = null;
 
diff --git a/backends/key-file/kf-persona-store.vala b/backends/key-file/kf-persona-store.vala
index 752343a..86c61f7 100644
--- a/backends/key-file/kf-persona-store.vala
+++ b/backends/key-file/kf-persona-store.vala
@@ -45,7 +45,8 @@ public class Folks.Backends.Kf.PersonaStore : Folks.PersonaStore
       "alias",
       "im-addresses",
       "web-service-addresses",
-      "anti-links"
+      "anti-links",
+      null /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=682698 */
     };
 
   internal static const string anti_links_key_name = "__anti-links";
diff --git a/backends/key-file/kf-persona.vala b/backends/key-file/kf-persona.vala
index 3a0b98a..8461f44 100644
--- a/backends/key-file/kf-persona.vala
+++ b/backends/key-file/kf-persona.vala
@@ -40,14 +40,16 @@ public class Folks.Backends.Kf.Persona : Folks.Persona,
   private const string[] _linkable_properties =
     {
       "im-addresses",
-      "web-service-addresses"
+      "web-service-addresses",
+      null /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=682698 */
     };
   private const string[] _writeable_properties =
     {
       "alias",
       "im-addresses",
       "web-service-addresses",
-      "anti-links"
+      "anti-links",
+      null /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=682698 */
     };
 
   /**
diff --git a/backends/libsocialweb/lib/swf-persona.vala b/backends/libsocialweb/lib/swf-persona.vala
index 1c22608..aceff83 100644
--- a/backends/libsocialweb/lib/swf-persona.vala
+++ b/backends/libsocialweb/lib/swf-persona.vala
@@ -41,7 +41,8 @@ public class Swf.Persona : Folks.Persona,
   private const string[] _linkable_properties =
     {
       "im-addresses",
-      "web-service-addresses"
+      "web-service-addresses",
+      null /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=682698 */
     };
 
   /* No writeable properties
diff --git a/backends/ofono/ofono-persona.vala b/backends/ofono/ofono-persona.vala
index f81230d..c0b720e 100644
--- a/backends/ofono/ofono-persona.vala
+++ b/backends/ofono/ofono-persona.vala
@@ -47,7 +47,8 @@ public class Folks.Backends.Ofono.Persona : Folks.Persona,
   private const string[] _linkable_properties =
     {
       "phone-numbers",
-      "email-addresses"
+      "email-addresses",
+      null /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=682698 */
     };
   private static string[] _writeable_properties = {};
 
diff --git a/backends/telepathy/lib/tpf-persona.vala b/backends/telepathy/lib/tpf-persona.vala
index 6a3cf55..8830158 100644
--- a/backends/telepathy/lib/tpf-persona.vala
+++ b/backends/telepathy/lib/tpf-persona.vala
@@ -49,7 +49,11 @@ public class Tpf.Persona : Folks.Persona,
     PresenceDetails,
     UrlDetails
 {
-  private const string[] _linkable_properties = { "im-addresses" };
+  private const string[] _linkable_properties =
+    {
+      "im-addresses",
+      null /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=682698 */
+    };
   private string[] _writeable_properties = null;
 
   /* Whether we've finished being constructed; this is used to prevent
diff --git a/backends/tracker/lib/trf-persona-store.vala b/backends/tracker/lib/trf-persona-store.vala
index f18b5be..5d5613e 100644
--- a/backends/tracker/lib/trf-persona-store.vala
+++ b/backends/tracker/lib/trf-persona-store.vala
@@ -305,7 +305,8 @@ public class Trf.PersonaStore : Folks.PersonaStore
       "im-addresses",
       "is-favourite",
       "local-ids",
-      "web-service-addresses"
+      "web-service-addresses",
+      null /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=682698 */
     };
 
   /**
diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala
index dcb37fa..770e044 100644
--- a/backends/tracker/lib/trf-persona.vala
+++ b/backends/tracker/lib/trf-persona.vala
@@ -48,7 +48,12 @@ public class Trf.Persona : Folks.Persona,
   private string _nickname; /* must never be null */
   private bool _is_favourite;
   private const string[] _linkable_properties =
-      {"im-addresses", "local-ids", "web-service-addresses"};
+    {
+      "im-addresses",
+      "local-ids",
+      "web-service-addresses",
+      null /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=682698 */
+    };
   private SmallSet<PhoneFieldDetails> _phone_numbers;
   private Set<PhoneFieldDetails> _phone_numbers_ro;
   private SmallSet<EmailFieldDetails> _email_addresses;
@@ -70,7 +75,8 @@ public class Trf.Persona : Folks.Persona,
       "im-addresses",
       "is-favourite",
       "local-ids",
-      "web-service-addresses"
+      "web-service-addresses",
+      null /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=682698 */
     };
 
   /**
diff --git a/folks/individual-aggregator.vala b/folks/individual-aggregator.vala
index f859491..b82b29c 100644
--- a/folks/individual-aggregator.vala
+++ b/folks/individual-aggregator.vala
@@ -1244,6 +1244,10 @@ public class Folks.IndividualAggregator : Object
                * attempt to link based on its linkable properties. */
               foreach (unowned string foo in persona.linkable_properties)
                 {
+                  /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=682698 */
+                  if (foo == null)
+                      continue;
+
                   /* FIXME: If we just use string prop_name directly in the
                    * foreach, Vala doesn't copy it into the closure data, and
                    * prop_name ends up as NULL. bgo#628336 */
@@ -1428,6 +1432,10 @@ public class Folks.IndividualAggregator : Object
     {
       foreach (var prop_name in persona.linkable_properties)
         {
+          /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=682698 */
+          if (prop_name == null)
+              continue;
+
           persona.notify[prop_name].connect (
               this._persona_linkable_property_changed_cb);
         }
@@ -1450,6 +1458,10 @@ public class Folks.IndividualAggregator : Object
 
       foreach (var prop_name in persona.linkable_properties)
         {
+          /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=682698 */
+          if (prop_name == null)
+              continue;
+
           persona.notify[prop_name].disconnect (
               this._persona_linkable_property_changed_cb);
         }
@@ -1502,6 +1514,10 @@ public class Folks.IndividualAggregator : Object
            * Individual. */
           foreach (unowned string prop_name in persona.linkable_properties)
             {
+              /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=682698 */
+              if (prop_name == null)
+                  continue;
+
               debug ("        %s", prop_name);
 
               /* FIXME: can't be var because of bgo#638208 */


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