Blame SOURCES/pidgin-2.10.7-CVE-2013-6483-regression.patch

abdd45
diff -up pidgin-2.10.7/libpurple/protocols/jabber/iq.c.CVE-2013-6483-regression pidgin-2.10.7/libpurple/protocols/jabber/iq.c
abdd45
--- pidgin-2.10.7/libpurple/protocols/jabber/iq.c.CVE-2013-6483-regression	2014-02-03 09:49:18.556521925 -0500
abdd45
+++ pidgin-2.10.7/libpurple/protocols/jabber/iq.c	2014-02-03 09:49:29.904554588 -0500
abdd45
@@ -283,6 +283,52 @@ void jabber_iq_remove_callback_by_id(Jab
abdd45
 	g_hash_table_remove(js->iq_callbacks, id);
abdd45
 }
abdd45
 
abdd45
+/**
abdd45
+ * Verify that the 'from' attribute of an IQ reply is a valid match for
abdd45
+ * a given IQ request. The expected behavior is outlined in section
abdd45
+ * 8.1.2.1 of the XMPP CORE spec (RFC 6120). We consider the reply to
abdd45
+ * be a valid match if any of the following is true:
abdd45
+ * - Request 'to' matches reply 'from' (including the case where
abdd45
+ *   neither are set).
abdd45
+ * - Request 'to' was empty and reply 'from' is server JID.
abdd45
+ * - Request 'to' was empty and reply 'from' is my JID. The spec says
abdd45
+ *   we should only allow bare JID, but we also allow full JID for
abdd45
+ *   compatibility with some servers.
abdd45
+ *
abdd45
+ * These rules should allow valid IQ replies while preventing spoofed
abdd45
+ * ones.
abdd45
+ *
abdd45
+ * For more discussion see the "Spoofing of iq ids and misbehaving
abdd45
+ * servers" email thread from January 2014 on the jdev and security
abdd45
+ * mailing lists.
abdd45
+ *
abdd45
+ * @return TRUE if this reply is valid for the given request.
abdd45
+ */
abdd45
+static gboolean does_reply_from_match_request_to(JabberStream *js, JabberID *to, JabberID *from)
abdd45
+{
abdd45
+	if (jabber_id_equal(to, from)) {
abdd45
+		/* Request 'to' matches reply 'from' */
abdd45
+		return TRUE;
abdd45
+	}
abdd45
+
abdd45
+	if (!to && purple_strequal(from->domain, js->user->domain)) {
abdd45
+		/* Request 'to' is empty and reply 'from' domain matches our domain */
abdd45
+
abdd45
+		if (!from->node && !from->resource) {
abdd45
+			/* Reply 'from' is server bare JID */
abdd45
+			return TRUE;
abdd45
+		}
abdd45
+
abdd45
+		if (purple_strequal(from->node, js->user->node)
abdd45
+				&& (!from->resource || purple_strequal(from->resource, js->user->resource))) {
abdd45
+			/* Reply 'from' is my full or bare JID */
abdd45
+			return TRUE;
abdd45
+		}
abdd45
+	}
abdd45
+
abdd45
+	return FALSE;
abdd45
+}
abdd45
+
abdd45
 void jabber_iq_parse(JabberStream *js, xmlnode *packet)
abdd45
 {
abdd45
 	JabberIqCallbackData *jcd;
abdd45
@@ -377,8 +423,9 @@ void jabber_iq_parse(JabberStream *js, x
abdd45
 
abdd45
 	/* First, lets see if a special callback got registered */
abdd45
 	if(type == JABBER_IQ_RESULT || type == JABBER_IQ_ERROR) {
abdd45
-		if((jcd = g_hash_table_lookup(js->iq_callbacks, id))) {
abdd45
-			if(jabber_id_equal(js, jcd->to, from_id)) {
abdd45
+		jcd = g_hash_table_lookup(js->iq_callbacks, id);
abdd45
+		if (jcd) {
abdd45
+			if (does_reply_from_match_request_to(js, jcd->to, from_id)) {
abdd45
 				jcd->callback(js, from, type, id, packet, jcd->data);
abdd45
 				jabber_iq_remove_callback_by_id(js, id);
abdd45
 				jabber_id_free(from_id);
abdd45
diff -up pidgin-2.10.7/libpurple/protocols/jabber/jutil.c.CVE-2013-6483-regression pidgin-2.10.7/libpurple/protocols/jabber/jutil.c
abdd45
--- pidgin-2.10.7/libpurple/protocols/jabber/jutil.c.CVE-2013-6483-regression	2014-02-03 09:49:18.558521926 -0500
abdd45
+++ pidgin-2.10.7/libpurple/protocols/jabber/jutil.c	2014-02-03 09:49:29.904554588 -0500
abdd45
@@ -510,30 +510,21 @@ jabber_id_free(JabberID *jid)
abdd45
 
abdd45
 
abdd45
 gboolean
abdd45
-jabber_id_equal(JabberStream *js, const JabberID *jid1, const JabberID *jid2)
abdd45
+jabber_id_equal(const JabberID *jid1, const JabberID *jid2)
abdd45
 {
abdd45
-	const JabberID *j1, *j2;
abdd45
-	JabberID *bare_user_jid;
abdd45
-	gboolean equal;
abdd45
-
abdd45
-	/* If an outgoing stanza has no 'to', or an incoming has no 'from',
abdd45
-	 * then those are "the server acting as my account". This function will
abdd45
-	 * handle that correctly.
abdd45
-	 */
abdd45
-	if (!jid1 && !jid2)
abdd45
+	if (!jid1 && !jid2) {
abdd45
+		/* Both are null therefore equal */
abdd45
 		return TRUE;
abdd45
+	}
abdd45
 
abdd45
-	bare_user_jid = jabber_id_to_bare_jid(js->user);
abdd45
-	j1 = jid1 ? jid1 : bare_user_jid;
abdd45
-	j2 = jid2 ? jid2 : bare_user_jid;
abdd45
-
abdd45
-	equal = purple_strequal(j1->node, j2->node) &&
abdd45
-			purple_strequal(j1->domain, j2->domain) &&
abdd45
-			purple_strequal(j1->resource, j2->resource);
abdd45
-
abdd45
-	jabber_id_free(bare_user_jid);
abdd45
-
abdd45
-	return equal;
abdd45
+	if (!jid1 || !jid2) {
abdd45
+		/* One is null, other is non-null, therefore not equal */
abdd45
+		return FALSE;
abdd45
+	}
abdd45
+
abdd45
+	return purple_strequal(jid1->node, jid2->node) &&
abdd45
+			purple_strequal(jid1->domain, jid2->domain) &&
abdd45
+			purple_strequal(jid1->resource, jid2->resource);
abdd45
 }
abdd45
 
abdd45
 char *jabber_get_domain(const char *in)
abdd45
diff -up pidgin-2.10.7/libpurple/protocols/jabber/jutil.h.CVE-2013-6483-regression pidgin-2.10.7/libpurple/protocols/jabber/jutil.h
abdd45
--- pidgin-2.10.7/libpurple/protocols/jabber/jutil.h.CVE-2013-6483-regression	2014-02-03 09:49:18.559521925 -0500
abdd45
+++ pidgin-2.10.7/libpurple/protocols/jabber/jutil.h	2014-02-03 09:49:29.904554588 -0500
abdd45
@@ -46,12 +46,10 @@ typedef enum {
abdd45
 JabberID* jabber_id_new(const char *str);
abdd45
 
abdd45
 /**
abdd45
- * Compare two JIDs for equality.
abdd45
- *
abdd45
- * Warning: If either JID is NULL then this function uses the user's
abdd45
- * bare JID, instead!
abdd45
+ * Compare two JIDs for equality. In addition to the node and domain,
abdd45
+ * the resources of the two JIDs must also be equal (or both absent).
abdd45
  */
abdd45
-gboolean jabber_id_equal(JabberStream *js, const JabberID *jid1, const JabberID *jid2);
abdd45
+gboolean jabber_id_equal(const JabberID *jid1, const JabberID *jid2);
abdd45
 
abdd45
 void jabber_id_free(JabberID *jid);
abdd45