pidgin.2.5.6: bd59a2a2: *** Plucked rev d34a1589 (darkrain42 at pid...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Wed Apr 29 17:01:28 EDT 2009


-----------------------------------------------------------------
Revision: bd59a2a2ed2d4dd5da976e3467553f3c6c31ddfc
Ancestor: 9faf059300757b58f58b0a6b919656ae67968e48
Author: darkrain42 at pidgin.im
Date: 2009-04-29T20:57:53
Branch: im.pidgin.pidgin.2.5.6
URL: http://d.pidgin.im/viewmtn/revision/info/bd59a2a2ed2d4dd5da976e3467553f3c6c31ddfc

Modified files:
        ChangeLog libpurple/protocols/bonjour/parser.c
        libpurple/protocols/jabber/jabber.c
        libpurple/protocols/jabber/parser.c
        libpurple/protocols/jabber/parser.h libpurple/xmlnode.c

ChangeLog: 

*** Plucked rev d34a1589 (darkrain42 at pidgin.im):
Feed a fake </stream:stream> to the XMPP parser to silence warnings.

Upgrading to TLS and disconnecting should no longer emit
	'Extra content at the end of the document'

References #8830.

*** Plucked rev ca9f6d5b (darkrain42 at pidgin.im):
Add xmlnode and bonjour structured error handlers.

Various libraries may set global structured error handlers and libxml2
prefers those to a per-context normal error handler.  This causes us to
break badly.

References #8830.

*** Plucked rev 34f4897e (darkrain42 at pidgin.im):
xmlCtxtGetLastError may return NULL, especially with other misbehaving
libraries in our address space.

References #8136.


-------------- next part --------------
============================================================
--- ChangeLog	257173ce6472b14d8da5f3cc3b46756a6718f60c
+++ ChangeLog	ab05c931008ac7fd7539cc6e78c75bad8fe99ea2
@@ -5,6 +5,9 @@ version 2.5.6 (??/??/2009):
 	* Improve sleep behavior by aggregation of longer timeouts on second
 	  boundaries to allow better power saving.  (Arunan Balasubramaniam)
 	* Fix various crashes on exit.
+	* Make XML parsing more resilient to interactions with other libraries.
+	  This, along with the fix for libxml2 bug 564217, fixes the crashes
+	  on connect in XMPP with recent gst-plugins-bad (see #8830 for details).
 
 	IRC:
 	* Correctly handle WHOIS for users who are joined to a large number of
============================================================
--- libpurple/protocols/bonjour/parser.c	2f4fc9959ef5e33edb692e66f8ef5417dbf1cb18
+++ libpurple/protocols/bonjour/parser.c	c9da9f2c11d8bf520a61f86f3b255ea22a50349f
@@ -156,6 +156,18 @@ bonjour_parser_element_text_libxml(void 
 	xmlnode_insert_data(bconv->current, (const char*) text, text_len);
 }
 
+static void
+bonjour_parser_structured_error_handler(void *user_data, xmlErrorPtr error)
+{
+	BonjourJabberConversation *bconv = user_data;
+
+	purple_debug_error("jabber", "XML parser error for BonjourJabberConversation %p: "
+	                             "Domain %i, code %i, level %i: %s",
+	                   bconv,
+	                   error->domain, error->code, error->level,
+	                   (error->message ? error->message : "(null)\n"));
+}
+
 static xmlSAXHandler bonjour_parser_libxml = {
 	NULL,									/*internalSubset*/
 	NULL,									/*isStandalone*/
@@ -188,7 +200,7 @@ static xmlSAXHandler bonjour_parser_libx
 	NULL,									/*_private*/
 	bonjour_parser_element_start_libxml,	/*startElementNs*/
 	bonjour_parser_element_end_libxml,		/*endElementNs*/
-	NULL									/*serror*/
+	bonjour_parser_structured_error_handler /*serror*/
 };
 
 void
============================================================
--- libpurple/protocols/jabber/jabber.c	ffa2b86a187b53e8e165af133466d0a7e5251046
+++ libpurple/protocols/jabber/jabber.c	d46b7fd23d8613f4c14bc2db9d85d781fc6fa030
@@ -77,6 +77,10 @@ static void jabber_stream_init(JabberStr
 						  "xmlns:stream='http://etherx.jabber.org/streams' "
 						  "version='1.0'>",
 						  js->user->domain);
+	if (js->reinit)
+		/* Close down the current stream to keep the XML parser happy */
+		jabber_parser_close_stream(js);
+
 	/* setup the parser fresh for each stream */
 	jabber_parser_setup(js);
 	jabber_send_raw(js, open_stream, -1);
@@ -636,6 +640,9 @@ static void tls_init(JabberStream *js)
 
 static void tls_init(JabberStream *js)
 {
+	/* Close down the current stream to keep the XML parser happy */
+	jabber_parser_close_stream(js);
+
 	purple_input_remove(js->gc->inpa);
 	js->gc->inpa = 0;
 	js->gsc = purple_ssl_connect_with_host_fd(js->gc->account, js->fd,
@@ -1327,6 +1334,16 @@ void jabber_close(PurpleConnection *gc)
 	if (!gc->disconnect_timeout)
 		jabber_send_raw(js, "</stream:stream>", -1);
 
+	if (!purple_account_get_current_error(purple_connection_get_account(gc))) {
+		/*
+		 * The common case is user-triggered, so we never receive a
+		 * </stream:stream> from the server when disconnecting, so silence the
+		 * parser's warnings. On errors, though, the server terminated the
+		 * connection, so we should have received a real </stream:stream>.
+		 */
+		jabber_parser_close_stream(js);
+	}
+
 	if (js->srv_query_data)
 		purple_srv_cancel(js->srv_query_data);
 
============================================================
--- libpurple/protocols/jabber/parser.c	194cd0b3cf0a5715df59a06101ccc520d9599a5a
+++ libpurple/protocols/jabber/parser.c	b04e8d86669d4d2be9fb2cda4186dd6bb87b6563
@@ -205,6 +205,12 @@ jabber_parser_setup(JabberStream *js)
 	jabber_parser_free(js);
 }
 
+void
+jabber_parser_close_stream(JabberStream *js)
+{
+	xmlParseChunk(js->context, "</stream:stream>", 16 /* length */, 0);
+}
+
 void jabber_parser_free(JabberStream *js) {
 	if (js->context) {
 		xmlParseChunk(js->context, NULL,0,1);
@@ -224,8 +230,17 @@ void jabber_parser_process(JabberStream 
 		xmlParseChunk(js->context, "", 0, 0);
 	} else if ((ret = xmlParseChunk(js->context, buf, len, 0)) != XML_ERR_OK) {
 		xmlError *err = xmlCtxtGetLastError(js->context);
+		/*
+		 * libxml2 uses a global setting to determine whether or not to store
+		 * warnings.  Other libraries may set this, which causes err to be
+		 * NULL. See #8136 for details.
+		 */
+		xmlErrorLevel level = XML_ERR_WARNING;
 
-		switch (err->level) {
+		if (err)
+			level = err->level;
+
+		switch (level) {
 			case XML_ERR_NONE:
 				purple_debug_info("jabber", "xmlParseChunk returned info %i\n", ret);
 				break;
============================================================
--- libpurple/protocols/jabber/parser.h	bbc239a21eaa581c3c7c3f5a0546b085b4699532
+++ libpurple/protocols/jabber/parser.h	f23d0e2a0aebd094f70f73aa4fb80ca5274646ae
@@ -25,6 +25,7 @@ void jabber_parser_setup(JabberStream *j
 #include "jabber.h"
 
 void jabber_parser_setup(JabberStream *js);
+void jabber_parser_close_stream(JabberStream *js);
 void jabber_parser_free(JabberStream *js);
 void jabber_parser_process(JabberStream *js, const char *buf, int len);
 
============================================================
--- libpurple/xmlnode.c	90698253f9e15bd5a840e8ddd792f60c0e1cfc0c
+++ libpurple/xmlnode.c	5d67f23f1d5be2817c457af01ea33de93a7887d6
@@ -665,6 +665,28 @@ xmlnode_parser_error_libxml(void *user_d
 	purple_debug_error("xmlnode", "Error parsing xml file: %s", errmsg);
 }
 
+static void
+xmlnode_parser_structural_error_libxml(void *user_data, xmlErrorPtr error)
+{
+	struct _xmlnode_parser_data *xpd = user_data;
+
+	if (error && (error->level == XML_ERR_ERROR ||
+	              error->level == XML_ERR_FATAL)) {
+		xpd->error = TRUE;
+		purple_debug_error("xmlnode", "XML parser error for xmlnode %p: "
+		                   "Domain %i, code %i, level %i: %s",
+		                   user_data, error->domain, error->code, error->level,
+		                   error->message ? error->message : "(null)\n");
+	} else if (error)
+		purple_debug_warning("xmlnode", "XML parser error for xmlnode %p: "
+		                     "Domain %i, code %i, level %i: %s",
+		                     user_data, error->domain, error->code, error->level,
+		                     error->message ? error->message : "(null)\n");
+	else
+		purple_debug_warning("xmlnode", "XML parser error for xmlnode %p\n",
+		                     user_data);
+}
+
 static xmlSAXHandler xmlnode_parser_libxml = {
 	NULL, /* internalSubset */
 	NULL, /* isStandalone */
@@ -697,7 +719,7 @@ static xmlSAXHandler xmlnode_parser_libx
 	NULL, /* _private */
 	xmlnode_parser_element_start_libxml, /* startElementNs */
 	xmlnode_parser_element_end_libxml,   /* endElementNs   */
-	NULL, /* serror */
+	xmlnode_parser_structural_error_libxml, /* serror */
 };
 
 xmlnode *


More information about the Commits mailing list