pidgin: 3ca58814: jabber: Fix a crash due to a contact hav...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Wed Aug 5 23:25:35 EDT 2009


-----------------------------------------------------------------
Revision: 3ca58814bdd8642da208ea36f34f9a752fd4bf1b
Ancestor: 3b6dec6dc5f2cd96c7e41e65f23002486061449f
Author: darkrain42 at pidgin.im
Date: 2009-08-06T03:21:59
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/3ca58814bdd8642da208ea36f34f9a752fd4bf1b

Modified files:
        libpurple/protocols/jabber/buddy.c

ChangeLog: 

jabber: Fix a crash due to a contact having a resource with jbr->name == NULL

This happens with legacy transports, when the transport sends presence
from the bare JID. This then crashes in g_str_hash when trying to look up
the jbr from the resource name. Fixes #9827.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/buddy.c	441a09259d0655f7f7cf90bc52d06bebeb4d88ea
+++ libpurple/protocols/jabber/buddy.c	ee71b63ec0e3ab62bb233c69ddcac515df96586a
@@ -1193,6 +1193,22 @@ static void jabber_buddy_info_resource_f
 	g_free(jbri);
 }
 
+static guint jbir_hash(gconstpointer v)
+{
+	if (v)
+		return g_str_hash(v);
+	else
+		return 0;
+}
+
+static gboolean jbir_equal(gconstpointer v1, gconstpointer v2)
+{
+	const gchar *resource_1 = v1;
+	const gchar *resource_2 = v2;
+
+	return purple_strequal(resource_1, resource_2);
+}
+
 static void jabber_version_parse(JabberStream *js, const char *from,
                                  JabberIqType type, const char *id,
                                  xmlnode *packet, gpointer data)
@@ -1464,9 +1480,7 @@ dispatch_queries_for_resource(JabberStre
 	char *full_jid = NULL;
 	const char *to;
 
-	g_return_if_fail(jbr->name != NULL);
-
-	if (is_bare_jid) {
+	if (is_bare_jid && jbr->name) {
 		full_jid = g_strdup_printf("%s/%s", jid, jbr->name);
 		to = full_jid;
 	} else
@@ -1535,7 +1549,7 @@ static void jabber_buddy_get_info_for_ji
 	jbi->jid = g_strdup(jid);
 	jbi->js = js;
 	jbi->jb = jb;
-	jbi->resources = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, jabber_buddy_info_resource_free);
+	jbi->resources = g_hash_table_new_full(jbir_hash, jbir_equal, g_free, jabber_buddy_info_resource_free);
 	jbi->user_info = purple_notify_user_info_new();
 
 	iq = jabber_iq_new(js, JABBER_IQ_GET);


More information about the Commits mailing list