[telepathy-gabble/master] Don't crash on an empty <nick/> node.
Will Thompson
will.thompson at collabora.co.uk
Tue May 19 09:42:29 PDT 2009
Fixes fd.o #21817
---
src/conn-aliasing.c | 15 ++++++++++++---
tests/twisted/vcard/test-alias-pep.py | 29 +++++++++++++++++++++++++++--
2 files changed, 39 insertions(+), 5 deletions(-)
diff --git a/src/conn-aliasing.c b/src/conn-aliasing.c
index 8d02a0d..4dd7759 100644
--- a/src/conn-aliasing.c
+++ b/src/conn-aliasing.c
@@ -607,14 +607,23 @@ _grab_nickname (GabbleConnection *self,
_cache_negatively (self, handle);
return FALSE;
}
- nickname = lm_message_node_get_value (node);
+ nickname = lm_message_node_get_value (node);
old = tp_handle_get_qdata (contact_handles, handle, quark);
if (tp_strdiff (old, nickname))
{
- tp_handle_set_qdata (contact_handles, handle, quark, g_strdup (nickname),
- g_free);
+ if (nickname == NULL)
+ {
+ DEBUG ("got empty <nick/> node, caching as NO_ALIAS");
+ _cache_negatively (self, handle);
+ }
+ else
+ {
+ tp_handle_set_qdata (contact_handles, handle, quark, g_strdup (nickname),
+ g_free);
+ }
+
gabble_conn_aliasing_nickname_updated ((GObject *) self, handle, self);
}
return TRUE;
diff --git a/tests/twisted/vcard/test-alias-pep.py b/tests/twisted/vcard/test-alias-pep.py
index 0375061..43f4b26 100644
--- a/tests/twisted/vcard/test-alias-pep.py
+++ b/tests/twisted/vcard/test-alias-pep.py
@@ -3,8 +3,8 @@
Test PEP alias support.
"""
-from servicetest import call_async, EventPattern, assertEquals
-from gabbletest import exec_test, make_result_iq, acknowledge_iq
+from servicetest import call_async, EventPattern, assertEquals, assertLength
+from gabbletest import exec_test, make_result_iq, acknowledge_iq, elem
import constants as cs
import ns
@@ -43,6 +43,31 @@ def test(q, bus, conn, stream):
# A second request should be satisfied from the cache.
assertEquals(['Bobby'], conn.Aliasing.RequestAliases([handle]))
+ # Bobby grows up, decides he hates his nickname.
+ # This is a regression test for
+ # <https://bugs.freedesktop.org/show_bug.cgi?id=21817>, where this would
+ # crash Gabble.
+ message = elem('message')(
+ elem((ns.PUBSUB + "#event"), 'event')(
+ elem('items', node=ns.NICK)(
+ elem('item')(
+ elem(ns.NICK, 'nick')
+ )
+ )
+ )
+ )
+ message['from'] = 'bob at foo.com' # thanks, Python
+ stream.send(message.toXml())
+
+ event = q.expect('dbus-signal', signal='AliasesChanged')
+ aliases = event.args[0]
+ assertLength(1, aliases)
+ h, a = aliases[0]
+ assertEquals(handle, h)
+ # The contact explicitly cleared their PEP nick; Gabble should fall back to
+ # their JID.
+ assertEquals(a, 'bob at foo.com')
+
conn.Disconnect()
q.expect('dbus-signal', signal='StatusChanged',
args=[cs.CONN_STATUS_DISCONNECTED, cs.CSR_REQUESTED]),
--
1.5.6.5
More information about the telepathy-commits
mailing list