changeset 25882:54dcfe059dd4

*** Plucked rev 3993504a (darkrain42@pidgin.im): Don't crash when a broken server sends us an occupant's presence with an empty resource. Closes #8361.
author Paul Aurich <paul@darkrain42.org>
date Sat, 02 May 2009 21:08:59 +0000
parents 13d8b6c6ae42
children 9931796e1765
files libpurple/protocols/jabber/presence.c
diffstat 1 files changed, 18 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/presence.c	Fri May 01 16:05:55 2009 +0000
+++ b/libpurple/protocols/jabber/presence.c	Sat May 02 21:08:59 2009 +0000
@@ -601,9 +601,11 @@
 		if(type && !strcmp(type, "unavailable")) {
 			gboolean nick_change = FALSE;
 
-			/* If we haven't joined the chat yet, we don't care that someone
-			 * left, or it was us leaving after we closed the chat */
-			if (!chat->conv || chat->left) {
+			/* If the chat nick is invalid, we haven't yet joined, or we've
+			 * already left (it was probably us leaving after we closed the
+			 * chat), we don't care.
+			 */
+			if (!jid->resource || !chat->conv || chat->left) {
 				if (chat->left &&
 						jid->resource && chat->handle && !strcmp(jid->resource, chat->handle))
 					jabber_chat_destroy(chat);
@@ -664,6 +666,19 @@
 				}
 			}
 		} else {
+			/*
+			 * XEP-0045 mandates the presence to include a resource (which is
+			 * treated as the chat nick). Some non-compliant servers allow
+			 * joining without a nick.
+			 */
+			if (!jid->resource) {
+				jabber_id_free(jid);
+				g_free(avatar_hash);
+				g_free(nickname);
+				g_free(status);
+				return;
+			}
+
 			if(!chat->conv) {
 				chat->id = i++;
 				chat->muc = muc;