pidgin: d3f24a7d: jabber: Don't crash on caps that include...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Fri Jul 9 18:50:52 EDT 2010


----------------------------------------------------------------------
Revision: d3f24a7d7c85e2f0a88f00386d16628b5eb17708
Parent:   fdc5dbeafbce28333163f1d850ec53d53a692149
Author:   darkrain42 at pidgin.im
Date:     07/09/10 18:49:17
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/d3f24a7d7c85e2f0a88f00386d16628b5eb17708

Changelog: 

jabber: Don't crash on caps that include an empty <value/> in the Software Information extended info.  Fixes #12292

(The part at fault is <field var='os_version'><value/></field>)

Changes against parent fdc5dbeafbce28333163f1d850ec53d53a692149

  patched  libpurple/protocols/jabber/caps.c
  patched  libpurple/tests/test_jabber_caps.c

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/caps.c	f48da1befffa10a258acea51fdbd778491b2cdc9
+++ libpurple/protocols/jabber/caps.c	7a5f5eda8a79d401dda5ee9287014728108f89ac
@@ -841,9 +841,12 @@ append_escaped_string(PurpleCipherContex
 static void 
 append_escaped_string(PurpleCipherContext *context, const gchar *str)
 {
-	char *tmp = g_markup_escape_text(str, -1);
-	purple_cipher_context_append(context, (const guchar *)tmp, strlen(tmp));
-	g_free(tmp);
+	if (str && *str) {
+		char *tmp = g_markup_escape_text(str, -1);
+		purple_cipher_context_append(context, (const guchar *)tmp, strlen(tmp));
+		g_free(tmp);
+	}
+
 	purple_cipher_context_append(context, (const guchar *)"<", 1);
 }
 
============================================================
--- libpurple/tests/test_jabber_caps.c	95427bb48ee20a114aab45f65dd980cbbaf27130
+++ libpurple/tests/test_jabber_caps.c	149a558502d2c36a221b8f46a1ee2fd4e4527d26
@@ -23,6 +23,20 @@ END_TEST
 }
 END_TEST
 
+#define assert_caps_calculate_match(hash_func, hash, str) { \
+	xmlnode *query = xmlnode_from_str((str), -1); \
+	JabberCapsClientInfo *info = jabber_caps_parse_client_info(query); \
+	gchar *got_hash = jabber_caps_calculate_hash(info, (hash_func)); \
+	assert_string_equal_free((hash), got_hash); \
+}
+
+START_TEST(test_calculate_caps)
+{
+	assert_caps_calculate_match("sha1", "GNjxthSckUNvAIoCCJFttjl6VL8=",
+	"<query xmlns='http://jabber.org/protocol/disco#info' node='http://tkabber.jabber.ru/#GNjxthSckUNvAIoCCJFttjl6VL8='><identity category='client' type='pc' name='Tkabber'/><x xmlns='jabber:x:data' type='result'><field var='FORM_TYPE' type='hidden'><value>urn:xmpp:dataforms:softwareinfo</value></field><field var='software'><value>Tkabber</value></field><field var='software_version'><value> ( 8.5.5 )</value></field><field var='os'><value>ATmega640-16AU</value></field><field var='os_version'><value/></field></x><feature var='games:board'/><feature var='google:mail:notify'/><feature var='http://jabber.org/protocol/activity'/><feature var='http://jabber.org/protocol/bytestreams'/><feature var='http://jabber.org/protocol/chatstates'/><feature var='http://jabber.org/protocol/commands'/><feature var='http://jabber.org/protocol/commands'/><feature var='http://jabber.org/protocol/disco#info'/><feature var='http://jabber.org/protocol/disco#items'/><feature var='http://jabber.org/protocol/feature-neg'/><feature var='http://jabber.org/protocol/geoloc'/><feature var='http://jabber.org/protocol/ibb'/><feature var='http://jabber.org/protocol/iqibb'/><feature var='http://jabber.org/protocol/mood'/><feature var='http://jabber.org/protocol/muc'/><feature var='http://jabber.org/protocol/mute#ancestor'/><feature var='http://jabber.org/protocol/mute#editor'/><feature var='http://jabber.org/protocol/rosterx'/><feature var='http://jabber.org/protocol/si'/><feature var='http://jabber.org/protocol/si/profile/file-transfer'/><feature var='http://jabber.org/protocol/tune'/><feature var='jabber:iq:avatar'/><feature var='jabber:iq:browse'/><feature var='jabber:iq:dtcp'/><feature var='jabber:iq:filexfer'/><feature var='jabber:iq:ibb'/><feature var='jabber:iq:inband'/><feature var='jabber:iq:jidlink'/><feature var='jabber:iq:last'/><feature var='jabber:iq:oob'/><feature var='jabber:iq:privacy'/><feature var='jabber:iq:time'/><feature var='jabber:iq:version'/><feature var='jabber:x:data'/><feature var='jabber:x:event'/><feature var='jabber:x:oob'/><feature var='urn:xmpp:ping'/><feature var='urn:xmpp:receipts'/><feature var='urn:xmpp:time'/></query>");
+}
+END_TEST
+
 Suite *
 jabber_caps_suite(void)
 {
@@ -32,5 +46,9 @@ jabber_caps_suite(void)
 	tcase_add_test(tc, test_parse_invalid);
 	suite_add_tcase(s, tc);
 
+	tc = tcase_create("Calculating from XMLnode");
+	tcase_add_test(tc, test_calculate_caps);
+	suite_add_tcase(s, tc);
+
 	return s;
 }


More information about the Commits mailing list