pidgin: c0fb4b16: jabber: Clear the stream header when res...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Tue Mar 16 22:36:05 EDT 2010


-----------------------------------------------------------------
Revision: c0fb4b16f604abbca72e2d063be8d03653d5aac2
Ancestor: cf59840fc04e1a2ee8115e4a1fef6cabe78075d2
Author: darkrain42 at pidgin.im
Date: 2010-03-12T06:25:15
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/c0fb4b16f604abbca72e2d063be8d03653d5aac2

Modified files:
        libpurple/protocols/jabber/jabber.c
        libpurple/protocols/jabber/jabber.h
        libpurple/protocols/jabber/parser.c

ChangeLog: 

jabber: Clear the stream header when restarting a stream, and be
much stricter about the first tag in a stream.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/jabber.c	a33cf4c1fa4164c605cbc2efa3648d899b58836e
+++ libpurple/protocols/jabber/jabber.c	d26dfae97f2279d855d9bfd62a9077c83851c798
@@ -86,6 +86,11 @@ static void jabber_stream_init(JabberStr
 {
 	char *open_stream;
 
+	if (js->stream_id) {
+		g_free(js->stream_id);
+		js->stream_id = NULL;
+	}
+
 	open_stream = g_strdup_printf("<stream:stream to='%s' "
 				          "xmlns='" NS_XMPP_CLIENT "' "
 						  "xmlns:stream='" NS_XMPP_STREAMS "' "
============================================================
--- libpurple/protocols/jabber/jabber.h	32b19839964f9c88391314585dc9b0d919bb9d87
+++ libpurple/protocols/jabber/jabber.h	d667d9c8a87e8c0c0475831decc2d5a5a99813a3
@@ -112,6 +112,13 @@ struct _JabberStream
 
 	JabberSaslMech *auth_mech;
 	gpointer auth_mech_data;
+	
+	/**
+	 * The header from the opening <stream/> tag.  This being NULL is treated
+	 * as a special condition in the parsing code (signifying the next
+	 * stanza started is an opening stream tag), and its being missing on
+	 * the stream header is treated as a fatal error.
+	 */
 	char *stream_id;
 	JabberStreamState state;
 
============================================================
--- libpurple/protocols/jabber/parser.c	f437ba12b5fb1072cb91af9c79f26b02933d0856
+++ libpurple/protocols/jabber/parser.c	cb0b0f6d7ce8ae78749be3b7aadeb1ca5143e939
@@ -43,10 +43,25 @@ jabber_parser_element_start_libxml(void 
 
 	if(!element_name) {
 		return;
-	} else if(!xmlStrcmp(element_name, (xmlChar*) "stream")) {
+	} else if (js->stream_id == NULL) {
+		/* Sanity checking! */
+		if (0 != xmlStrcmp(element_name, (xmlChar *) "stream") ||
+				0 != xmlStrcmp(namespace, (xmlChar *) NS_XMPP_STREAMS)) {
+			/* We were expecting a <stream:stream/> opening stanza, but
+			 * didn't get it. Bad!
+			 */
+			purple_debug_error("jabber", "Expecting stream header, got %s with "
+			                   "xmlns %s\n", element_name, namespace);
+			purple_connection_error_reason(js->gc,
+					PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE,
+					_("XMPP stream header missing"));
+			return;
+		}
+
 		js->protocol_version.major = 0;
 		js->protocol_version.minor = 9;
-		for(i=0; i < nb_attributes * 5; i += 5) {
+
+		for (i = 0; i < nb_attributes * 5; i += 5) {
 			int attrib_len = attributes[i+4] - attributes[i+3];
 			char *attrib = g_strndup((gchar *)attributes[i+3], attrib_len);
 
@@ -56,11 +71,14 @@ jabber_parser_element_start_libxml(void 
 				js->protocol_version.major = atoi(attrib);
 				js->protocol_version.minor = dot ? atoi(dot + 1) : 0;
 
-				if (js->protocol_version.major > 1)
+				if (js->protocol_version.major > 1) {
 					/* TODO: Send <unsupported-version/> error */
 					purple_connection_error_reason(js->gc,
 							PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE,
 							_("XMPP Version Mismatch"));
+					g_free(attrib);
+					return;
+				}
 
 				if (js->protocol_version.major == 0 && js->protocol_version.minor != 9) {
 					purple_debug_warning("jabber", "Treating version %s as 0.9 for backward "
@@ -74,6 +92,11 @@ jabber_parser_element_start_libxml(void 
 				g_free(attrib);
 			}
 		}
+
+		if (js->stream_id == NULL)
+			purple_connection_error_reason(js->gc,
+					PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE,
+					_("XMPP stream missing ID"));
 	} else {
 
 		if(js->current)


More information about the Commits mailing list