[telepathy-mission-control/master] McdConnection: if no fallbacks for a presence are supported, twice, don't crash

Simon McVittie simon.mcvittie at collabora.co.uk
Thu Jul 9 06:06:51 PDT 2009


The first time this happened, we'd overwrite the NULL at the end of
one of the fallbacks arrays (e.g. _away_fb[1]) with a pointer to
"available". Then, the *second* time it happened, we'd iterate off the end
of the array (since it would no longer have a NULL terminator), try to
dereference some random memory as a char* in g_str_hash, and crash.
---
 src/mcd-connection.c |   22 ++++++++++++++++------
 1 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/mcd-connection.c b/src/mcd-connection.c
index 1a0b4ba..bac6e70 100644
--- a/src/mcd-connection.c
+++ b/src/mcd-connection.c
@@ -226,13 +226,23 @@ _check_presence (McdConnectionPrivate *priv, TpConnectionPresenceType presence,
 
     /* assume that "available" is always supported -- otherwise, an error will
      * be returned by SetPresence, but it's not a big loss */
-    if (*fallbacks == NULL)
-        *fallbacks = "available";
 
-    DEBUG ("account %s: presence %s not supported, setting %s",
-           mcd_account_get_unique_name (priv->account),
-           *status, *fallbacks);
-    *status = *fallbacks;
+    if (*fallbacks != NULL)
+    {
+        DEBUG ("account %s: presence %s not supported, setting %s",
+               mcd_account_get_unique_name (priv->account), *status,
+               *fallbacks);
+        *status = *fallbacks;
+    }
+    else
+    {
+        DEBUG ("account %s: presence %s not supported and no fallback is "
+               "supported either, trying \"available\" and hoping for the "
+               "best...", mcd_account_get_unique_name (priv->account),
+               *status);
+        *status = "available";
+    }
+
     return TRUE;
 }
 
-- 
1.5.6.5




More information about the telepathy-commits mailing list