changeset 28421:a335d1bab20e

jabber: Reject invalid chat nicks in /nick command. Fixes #10532.
author Paul Aurich <paul@darkrain42.org>
date Sat, 24 Oct 2009 00:59:12 +0000
parents eec2df4b9a2d
children 44cbfcaf9e3a 318ac22eb05d
files libpurple/protocols/jabber/chat.c libpurple/protocols/jabber/chat.h libpurple/protocols/jabber/jabber.c
diffstat 3 files changed, 17 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/chat.c	Fri Oct 23 06:25:49 2009 +0000
+++ b/libpurple/protocols/jabber/chat.c	Sat Oct 24 00:59:12 2009 +0000
@@ -692,11 +692,11 @@
 }
 
 
-void jabber_chat_change_nick(JabberChat *chat, const char *nick)
+gboolean jabber_chat_change_nick(JabberChat *chat, const char *nick)
 {
 	xmlnode *presence;
 	char *full_jid;
-	PurplePresence *gpresence;
+	PurpleAccount *account;
 	PurpleStatus *status;
 	JabberBuddyState state;
 	char *msg;
@@ -706,11 +706,11 @@
 		purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), "",
 				_("Nick changing not supported in non-MUC chatrooms"),
 				PURPLE_MESSAGE_SYSTEM, time(NULL));
-		return;
+		return FALSE;
 	}
 
-	gpresence = purple_account_get_presence(chat->js->gc->account);
-	status = purple_presence_get_active_status(gpresence);
+	account = purple_connection_get_account(chat->js->gc);
+	status = purple_account_get_active_status(account);
 
 	purple_status_to_jabber(status, &state, &msg, &priority);
 
@@ -722,6 +722,8 @@
 
 	jabber_send(chat->js, presence);
 	xmlnode_free(presence);
+
+	return TRUE;
 }
 
 void jabber_chat_part(JabberChat *chat, const char *msg)
--- a/libpurple/protocols/jabber/chat.h	Fri Oct 23 06:25:49 2009 +0000
+++ b/libpurple/protocols/jabber/chat.h	Sat Oct 24 00:59:12 2009 +0000
@@ -89,7 +89,7 @@
 void jabber_chat_register(JabberChat *chat);
 void jabber_chat_change_topic(JabberChat *chat, const char *topic);
 void jabber_chat_set_topic(PurpleConnection *gc, int id, const char *topic);
-void jabber_chat_change_nick(JabberChat *chat, const char *nick);
+gboolean jabber_chat_change_nick(JabberChat *chat, const char *nick);
 void jabber_chat_part(JabberChat *chat, const char *msg);
 void jabber_chat_track_handle(JabberChat *chat, const char *handle,
 		const char *jid, const char *affiliation, const char *role);
--- a/libpurple/protocols/jabber/jabber.c	Fri Oct 23 06:25:49 2009 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Sat Oct 24 00:59:12 2009 +0000
@@ -2606,8 +2606,15 @@
 	if(!chat || !args || !args[0])
 		return PURPLE_CMD_RET_FAILED;
 
-	jabber_chat_change_nick(chat, args[0]);
-	return PURPLE_CMD_RET_OK;
+	if (!jabber_resourceprep_validate(args[0])) {
+		*error = g_strdup(_("Invalid nickname"));
+		return PURPLE_CMD_RET_FAILED;
+	}
+
+	if (jabber_chat_change_nick(chat, args[0]))
+		return PURPLE_CMD_RET_OK;
+	else
+		return PURPLE_CMD_RET_FAILED;
 }
 
 static PurpleCmdRet jabber_cmd_chat_part(PurpleConversation *conv,