Blame SOURCES/pidgin-2.10.7-CVE-2013-6481.patch

4133dc
diff -up pidgin-2.10.7/libpurple/protocols/yahoo/libymsg.c.CVE-2013-6481 pidgin-2.10.7/libpurple/protocols/yahoo/libymsg.c
4133dc
--- pidgin-2.10.7/libpurple/protocols/yahoo/libymsg.c.CVE-2013-6481	2014-01-27 10:20:14.473648650 -0500
4133dc
+++ pidgin-2.10.7/libpurple/protocols/yahoo/libymsg.c	2014-01-28 20:57:13.990365865 -0500
4133dc
@@ -2720,7 +2720,7 @@ static void yahoo_p2p_read_pkt_cb(gpoint
4133dc
 	int pos = 0;
4133dc
 	int pktlen;
4133dc
 	struct yahoo_packet *pkt;
4133dc
-	guchar *start = NULL;
4133dc
+	guchar *start;
4133dc
 	struct yahoo_p2p_data *p2p_data;
4133dc
 	YahooData *yd;
4133dc
 
4133dc
@@ -2742,19 +2742,29 @@ static void yahoo_p2p_read_pkt_cb(gpoint
4133dc
 		return;
4133dc
 	}
4133dc
 
4133dc
+	/* TODO: It looks like there's a bug here (and above) where an incorrect
4133dc
+	 * assumtion is being made that the buffer will be added to when this
4133dc
+	 * is next called, but that's not really the case! */
4133dc
 	if(len < YAHOO_PACKET_HDRLEN)
4133dc
 		return;
4133dc
 
4133dc
-	if(strncmp((char *)buf, "YMSG", MIN(4, len)) != 0) {
4133dc
+	if(strncmp((char *)buf, "YMSG", 4) != 0) {
4133dc
 		/* Not a YMSG packet */
4133dc
-		purple_debug_warning("yahoo","p2p: Got something other than YMSG packet\n");
4133dc
+		purple_debug_warning("yahoo", "p2p: Got something other than YMSG packet\n");
4133dc
 
4133dc
-		start = memchr(buf + 1, 'Y', len - 1);
4133dc
-		if (start == NULL)
4133dc
+		start = (guchar *) g_strstr_len((char *) buf + 1, len - 1 ,"YMSG");
4133dc
+		if (start == NULL) {
4133dc
+			/* remove from p2p connection lists, also calls yahoo_p2p_disconnect_destroy_data */
4133dc
+			if (g_hash_table_lookup(yd->peers, p2p_data->host_username))
4133dc
+				g_hash_table_remove(yd->peers, p2p_data->host_username);
4133dc
+			else
4133dc
+				yahoo_p2p_disconnect_destroy_data(data);
4133dc
 			return;
4133dc
+		}
4133dc
+		purple_debug_warning("yahoo","p2p: Got something other than YMSG packet\n");
4133dc
 
4133dc
-		g_memmove(buf, start, len - (start - buf));
4133dc
-		len -= start - buf;
4133dc
+		len -= (start - buf);
4133dc
+		g_memmove(buf, start, len);
4133dc
 	}
4133dc
 
4133dc
 	pos += 4;	/* YMSG */
4133dc
@@ -2762,7 +2772,17 @@ static void yahoo_p2p_read_pkt_cb(gpoint
4133dc
 	pos += 2;
4133dc
 
4133dc
 	pktlen = yahoo_get16(buf + pos); pos += 2;
4133dc
-	purple_debug_misc("yahoo", "p2p: %d bytes to read\n", len);
4133dc
+	if (len < (YAHOO_PACKET_HDRLEN + pktlen)) {
4133dc
+		purple_debug_error("yahoo", "p2p: packet length(%d) > buffer length(%d)\n",
4133dc
+				pktlen, (len - pos)); 
4133dc
+		/* remove from p2p connection lists, also calls yahoo_p2p_disconnect_destroy_data */
4133dc
+		if (g_hash_table_lookup(yd->peers, p2p_data->host_username))
4133dc
+			g_hash_table_remove(yd->peers, p2p_data->host_username);
4133dc
+		else
4133dc
+			yahoo_p2p_disconnect_destroy_data(data);
4133dc
+		return;
4133dc
+	} else
4133dc
+		purple_debug_misc("yahoo", "p2p: %d bytes to read\n", pktlen);
4133dc
 
4133dc
 	pkt = yahoo_packet_new(0, 0, 0);
4133dc
 	pkt->service = yahoo_get16(buf + pos); pos += 2;