pidgin: d005f564: Various BOSH fixes

darkrain42 at pidgin.im darkrain42 at pidgin.im
Fri May 22 01:35:49 EDT 2009


-----------------------------------------------------------------
Revision: d005f5640fbc5f61eb1f5d43affe9838a9ef2b3e
Ancestor: 60c1ce6b0f129eaef5053f2ef82976f75b6ce6ca
Author: darkrain42 at pidgin.im
Date: 2009-05-22T03:48:19
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/d005f5640fbc5f61eb1f5d43affe9838a9ef2b3e

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

ChangeLog: 

Various BOSH fixes

Corner case where a packet arrives that includes "Content-Lenght: " but not
the end of the line (extreme corner case).
Don't crash if the BOSH version doesn't include a '.'


-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/bosh.c	21caeb2e8ff912502852b10e7911ec725903fdee
+++ libpurple/protocols/jabber/bosh.c	085ceff0e1a20308c1410164e79380772b494f51
@@ -448,11 +448,14 @@ static void boot_response_cb(PurpleBOSHC
 
 	if (version) {
 		const char *dot = strstr(version, ".");
-		int major = atoi(version);
-		int minor = atoi(dot + 1);
+		int major, minor = 0;
 
 		purple_debug_info("jabber", "BOSH connection manager version %s\n", version);
 
+		major = atoi(version);
+		if (dot)
+			minor = atoi(dot + 1);
+
 		if (major != 1 || minor < 6) {
 			purple_connection_error_reason(conn->js->gc,
 			        PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
@@ -627,12 +630,23 @@ jabber_bosh_http_connection_process(Purp
 
 	if (!conn->headers_done) {
 		const char *content_length = purple_strcasestr(cursor, "\r\nContent-Length");
-		const char *end_of_headers = purple_strcasestr(cursor, "\r\n\r\n");
+		const char *end_of_headers = strstr(cursor, "\r\n\r\n");
 
 		/* Make sure Content-Length is in headers, not body */
-		if (content_length && content_length < end_of_headers) {
-			char *sep = strstr(content_length, ": ");
-			int len = atoi(sep + 2);
+		if (content_length && (!end_of_headers || content_length < end_of_headers)) {
+			const char *sep;
+			const char *eol;
+			int len;
+
+			if ((sep = strstr(content_length, ": ")) == NULL ||
+					(eol = strstr(sep, "\r\n")) == NULL)
+				/*
+				 * The packet ends in the middle of the Content-Length line.
+				 * We'll try again later when we have more.
+				 */
+				return;
+
+			len = atoi(sep + 2);
 			if (len == 0) 
 				purple_debug_warning("jabber", "Found mangled Content-Length header.\n");
 
@@ -688,21 +702,18 @@ http_connection_read(PurpleHTTPConnectio
 	if (!conn->buf)
 		conn->buf = g_string_new(NULL);
 
-	/* Read once to prime cnt before the loop */
-	if (conn->psc)
-		cnt = purple_ssl_read(conn->psc, buffer, sizeof(buffer));
-	else
-		cnt = read(conn->fd, buffer, sizeof(buffer));
-	while (cnt > 0) {
-		count += cnt;
-		g_string_append_len(conn->buf, buffer, cnt);
-
+	do {
 		if (conn->psc)
 			cnt = purple_ssl_read(conn->psc, buffer, sizeof(buffer));
 		else
 			cnt = read(conn->fd, buffer, sizeof(buffer));
-	}
 
+		if (cnt > 0) {
+			count += cnt;
+			g_string_append_len(conn->buf, buffer, cnt);
+		}
+	} while (cnt > 0);
+
 	if (cnt == 0 || (cnt < 0 && errno != EAGAIN)) {
 		if (cnt < 0)
 			purple_debug_info("jabber", "bosh read=%d, errno=%d, error=%s\n",


More information about the Commits mailing list