changeset 31082:86598f5d7ebd

Yahoo: Fix a crash that happens when the PurpleAccount disconnects after purple_network_listen() is called in yahoo_send_p2p_pkt(), but before the callback for purple_network_listen() is called. This solution isn't perfect-- it will almost certainly fall flat on its face if yahoo_send_p2p_packet() is called twice in a row--but doesn't make matters worse. Fixes #12432. committer: John Bailey <rekkanoryo@rekkanoryo.org>
author hanzz@soc.pidgin.im
date Thu, 30 Dec 2010 01:22:52 +0000
parents e023b0378887
children dd2f19faee14
files ChangeLog libpurple/protocols/yahoo/libymsg.c libpurple/protocols/yahoo/libymsg.h
diffstat 3 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Dec 30 01:06:03 2010 +0000
+++ b/ChangeLog	Thu Dec 30 01:22:52 2010 +0000
@@ -24,6 +24,10 @@
 	QQ:
 	* QQ2008 is now the default protocol version. (Michael Terry) (#11635)
 
+	Yahoo!/Yahoo! JAPAN:
+	* Fix a crash when an account disconnects before a p2p session is
+	  completely set up. (Jan Kaluza) (#12432)
+
 version 2.7.9 (12/26/2010):
 	MSN:
 	* Fix a crash when receiving short packets related to P2Pv2. (CVE ID
--- a/libpurple/protocols/yahoo/libymsg.c	Thu Dec 30 01:06:03 2010 +0000
+++ b/libpurple/protocols/yahoo/libymsg.c	Thu Dec 30 01:22:52 2010 +0000
@@ -2673,14 +2673,15 @@
 	if(!(p2p_data = data))
 		return ;
 
+	yd = p2p_data->gc->proto_data;
+	yd->listen_data = NULL;
+
 	if(listenfd == -1) {
 		purple_debug_warning("yahoo","p2p: error starting p2p server\n");
 		yahoo_p2p_disconnect_destroy_data(data);
 		return;
 	}
 
-	yd = p2p_data->gc->proto_data;
-
 	/* Add an Input Read event to the file descriptor */
 	yd->yahoo_local_p2p_server_fd = listenfd;
 	yd->yahoo_p2p_server_watcher = purple_input_add(listenfd, PURPLE_INPUT_READ, yahoo_p2p_server_send_connected_cb,data);
@@ -2759,8 +2760,15 @@
 	p2p_data->connection_type = YAHOO_P2P_WE_ARE_SERVER;
 	p2p_data->source = -1;
 
-	/* FIXME: Shouldn't this deal with the PurpleNetworkListenData* */
-	purple_network_listen(YAHOO_PAGER_PORT_P2P, SOCK_STREAM, yahoo_p2p_server_listen_cb, p2p_data);
+	/* FIXME: If the port is already used, purple_network_listener returns NULL and old listener won't be canceled
+	 * in yahoo_close function. */
+	if (yd->listen_data)
+		purple_debug_warning("yahoo","p2p: Failed to create p2p server - server already exists\n");
+	else {
+		yd->listen_data = purple_network_listen(YAHOO_PAGER_PORT_P2P, SOCK_STREAM, yahoo_p2p_server_listen_cb, p2p_data);
+		if (yd->listen_data == NULL)
+			purple_debug_warning("yahoo","p2p: Failed to created p2p server\n");
+	}
 
 	g_free(base64_ip);
 }
@@ -3784,6 +3792,8 @@
 		yahoo_buddy_icon_upload_data_free(yd->picture_upload_todo);
 	if (yd->ycht)
 		ycht_connection_close(yd->ycht);
+	if (yd->listen_data != NULL)
+		purple_network_listen_cancel(yd->listen_data);
 
 	g_free(yd->pending_chat_room);
 	g_free(yd->pending_chat_id);
--- a/libpurple/protocols/yahoo/libymsg.h	Thu Dec 30 01:06:03 2010 +0000
+++ b/libpurple/protocols/yahoo/libymsg.h	Thu Dec 30 01:22:52 2010 +0000
@@ -28,6 +28,7 @@
 #include "circbuffer.h"
 #include "cmds.h"
 #include "prpl.h"
+#include "network.h"
 
 #define YAHOO_PAGER_HOST_REQ_URL "http://vcs1.msg.yahoo.com/capacity"
 #define YAHOO_PAGER_HOST_FALLBACK "scsa.msg.yahoo.com"
@@ -243,6 +244,7 @@
 	GSList *url_datas;
 	GHashTable *xfer_peer_idstring_map;/* Hey, i dont know, but putting this HashTable next to friends gives a run time fault... */
 	GSList *cookies;/* contains all cookies, including _y and _t */
+	PurpleNetworkListenData *listen_data;
 
 	/**
 	 * We may receive a list15 in multiple packets with no prior warning as to how many we'll be getting;