[polari] Add bounds check so that the code doesn't segfault



commit 65240125541518c2916f53e10478ca8d504dc4f1
Author: Daniel Landau <daniel landau fi>
Date:   Mon Feb 22 23:03:23 2016 +0200

    Add bounds check so that the code doesn't segfault
    
    https://bugzilla.gnome.org/show_bug.cgi?id=762490

 src/lib/polari-room.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)
---
diff --git a/src/lib/polari-room.c b/src/lib/polari-room.c
index ea4450f..17045a8 100644
--- a/src/lib/polari-room.c
+++ b/src/lib/polari-room.c
@@ -321,9 +321,17 @@ on_group_contacts_changed (TpChannel  *channel,
   switch (reason)
     {
     case TP_CHANNEL_GROUP_CHANGE_REASON_RENAMED:
-      g_signal_emit (user_data, signals[MEMBER_RENAMED], 0,
-                     g_ptr_array_index (removed, 0),
-                     g_ptr_array_index (added, 0));
+
+      if (removed->len != 1 || added->len != 1) {
+        const char *removed_alias = removed->len > 0 ? tp_contact_get_alias (g_ptr_array_index (removed, 0)) 
: "undefined";
+        const char *added_alias = added->len > 0 ? tp_contact_get_alias (g_ptr_array_index (added, 0)) : 
"undefined";
+        g_warning ("Renamed '%s' to '%s'. Expected to have 1 removed and 1 added, but got %u removed and %u 
added",
+                   removed_alias, added_alias, removed->len, added->len);
+      } else {
+        g_signal_emit (user_data, signals[MEMBER_RENAMED], 0,
+                       g_ptr_array_index (removed, 0),
+                       g_ptr_array_index (added, 0));
+      }
       break;
     case TP_CHANNEL_GROUP_CHANGE_REASON_OFFLINE:
       for (i = 0; i < removed->len; i++)


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