[telepathy-gabble/telepathy-gabble-0.8] fix corner cases in handling of language key for location data

Dafydd Harries dafydd.harries at collabora.co.uk
Wed Sep 16 10:41:17 PDT 2009


This fixes several problems in add_to_geoloc_node():

 - A NULL pointer would be dereferenced if the language value was one of the
   types checked for, but not a string.
 - An assertion would fail if the language value wasn't a string or one of the
   other types checked for.
 - Coverity flagged a possible dereference of the mapping pointer when it was
   NULL, but in practice we'd already returned in that case. Hopefully the
   code should be less confusing for both Coverity and humans now.
---
 src/conn-location.c |   30 ++++++++++++++++++++----------
 1 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/src/conn-location.c b/src/conn-location.c
index 4238da9..84bbda4 100644
--- a/src/conn-location.c
+++ b/src/conn-location.c
@@ -188,9 +188,27 @@ add_to_geoloc_node (const gchar *tp_name,
   LocationMapping *mapping;
   gchar *str = NULL;
 
+  /* Map "language" to the xml:lang attribute. */
+  if (!tp_strdiff (tp_name, "language"))
+    {
+      if (G_VALUE_TYPE (value) != G_TYPE_STRING)
+        {
+#define ERROR_MSG "expecting string for language value, but got %s",\
+              G_VALUE_TYPE_NAME (value)
+          DEBUG (ERROR_MSG);
+          g_set_error (err, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT, ERROR_MSG);
+#undef ERROR_MSG
+          return FALSE;
+        }
+
+      lm_message_node_set_attribute (
+          geoloc, "xml:lang", g_value_get_string (value));
+      return TRUE;
+    }
+
   mapping = g_hash_table_lookup (tp_to_xmpp, tp_name);
-  if (mapping == NULL &&
-      tp_strdiff (tp_name, "language"))
+
+  if (mapping == NULL)
     {
       DEBUG ("Unknown location key: %s ; skipping", (const gchar *) tp_name);
       /* We don't raise a D-Bus error if the key is unknown to stay backward
@@ -225,14 +243,6 @@ add_to_geoloc_node (const gchar *tp_name,
   else if (G_VALUE_TYPE (value) == G_TYPE_STRING)
     {
       str = g_value_dup_string (value);
-
-      if (!tp_strdiff (tp_name, "language"))
-        {
-          /* Set the xml:lang */
-          lm_message_node_set_attribute (geoloc, "xml:lang", str);
-          g_free (str);
-          return TRUE;
-        }
     }
   else
     /* Keys and their type have been checked */
-- 
1.5.6.5




More information about the telepathy-commits mailing list