im.pidgin.pidgin: 1095e0c294d15e95c8909d270748c5253226bfe6

datallah at pidgin.im datallah at pidgin.im
Tue Oct 9 19:50:51 EDT 2007


-----------------------------------------------------------------
Revision: 1095e0c294d15e95c8909d270748c5253226bfe6
Ancestor: 9207c76719cf14838d6306432140b3f0da9225ae
Author: datallah at pidgin.im
Date: 2007-10-09T23:01:11
Branch: im.pidgin.pidgin

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

ChangeLog: 

Fix CID 337, null pointer deref.  Also plug a leak.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/jabber.c	e39ce8a439b5cd10ccdb7bf35ad08122c9c7a4ad
+++ libpurple/protocols/jabber/jabber.c	218b51943e20baf575458b7ddca8d6429a2cb120
@@ -2189,57 +2189,69 @@ static PurpleCmdRet jabber_cmd_ping(Purp
 	return PURPLE_CMD_RET_OK;
 }
 
-static PurpleCmdRet jabber_cmd_buzz(PurpleConversation *conv,
-		const char *cmd, char **args, char **error, void *data)
-{
-	JabberStream *js = conv->account->gc->proto_data;
-	xmlnode *msg, *buzz;
+static gboolean _jabber_send_buzz(JabberStream *js, const char *username, char **error) {
+
 	JabberBuddy *jb;
 	JabberBuddyResource *jbr;
-	char *to;
 	GList *iter;
 
-	if(!args || !args[0])
-		return PURPLE_CMD_RET_FAILED;
-	
-	jb = jabber_buddy_find(js, args[0], FALSE);
+	if(!username)
+		return FALSE;
+
+	jb = jabber_buddy_find(js, username, FALSE);
 	if(!jb) {
-		*error = g_strdup_printf(_("Unable to buzz, because there is nothing known about user %s."), args[0]);
-		return PURPLE_CMD_RET_FAILED;
+		*error = g_strdup_printf(_("Unable to buzz, because there is nothing known about user %s."), username);
+		return FALSE;
 	}
-	
+
 	jbr = jabber_buddy_find_resource(jb, NULL);
 	if(!jbr) {
-		*error = g_strdup_printf(_("Unable to buzz, because user %s might be offline."), args[0]);
-		return PURPLE_CMD_RET_FAILED;
+		*error = g_strdup_printf(_("Unable to buzz, because user %s might be offline."), username);
+		return FALSE;
 	}
+
 	if(!jbr->caps) {
-		*error = g_strdup_printf(_("Unable to buzz, because there is nothing known about user %s."), args[0]);
-		return PURPLE_CMD_RET_FAILED;
+		*error = g_strdup_printf(_("Unable to buzz, because there is nothing known about user %s."), username);
+		return FALSE;
 	}
+
 	for(iter = jbr->caps->features; iter; iter = g_list_next(iter)) {
 		if(!strcmp(iter->data, "http://www.xmpp.org/extensions/xep-0224.html#ns")) {
-			msg = xmlnode_new("message");
-			to = g_strdup_printf("%s/%s", args[0], jbr->name);
-			xmlnode_set_attrib(msg,"to",to);
+			xmlnode *buzz, *msg = xmlnode_new("message");
+			gchar *to;
+
+			to = g_strdup_printf("%s/%s", username, jbr->name);
+			xmlnode_set_attrib(msg, "to", to);
 			g_free(to);
-			
+
 			/* avoid offline storage */
-			xmlnode_set_attrib(msg,"type","headline");
-			
-			buzz = xmlnode_new_child(msg,"attention");
-			xmlnode_set_namespace(buzz,"http://www.xmpp.org/extensions/xep-0224.html#ns");
-			
-			jabber_send(js,msg);
+			xmlnode_set_attrib(msg, "type", "headline");
+
+			buzz = xmlnode_new_child(msg, "attention");
+			xmlnode_set_namespace(buzz, "http://www.xmpp.org/extensions/xep-0224.html#ns");
+
+			jabber_send(js, msg);
 			xmlnode_free(msg);
-			
-			return PURPLE_CMD_RET_OK;
+
+			return TRUE;
 		}
 	}
-	*error = g_strdup_printf(_("Unable to buzz, because the user %s does not support it."), args[0]);
-	return PURPLE_CMD_RET_FAILED;
+
+	*error = g_strdup_printf(_("Unable to buzz, because the user %s does not support it."), username);
+	return FALSE;
 }
 
+static PurpleCmdRet jabber_cmd_buzz(PurpleConversation *conv,
+		const char *cmd, char **args, char **error, void *data)
+{
+	JabberStream *js = conv->account->gc->proto_data;
+
+	if(!args || !args[0])
+		return PURPLE_CMD_RET_FAILED;
+
+	return _jabber_send_buzz(js, args[0], error)  ? PURPLE_CMD_RET_OK : PURPLE_CMD_RET_FAILED;
+}
+
 GList *jabber_attention_types(PurpleAccount *account)
 {
 	static GList *types = NULL;
@@ -2258,23 +2270,16 @@ gboolean jabber_send_attention(PurpleCon
 
 gboolean jabber_send_attention(PurpleConnection *gc, const char *username, guint code)
 {
-	PurpleConversation *conv;
-	char *error;
-	char *args[1];
-	PurpleCmdRet ret;
+	JabberStream *js = gc->proto_data;
+	gchar *error = NULL;
 
-	conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_ANY, username, gc->account);
-
-	args[0] = (char *)username;
-
-	ret = jabber_cmd_buzz(conv, "buzz", args, &error, NULL);
-
-	if (ret == PURPLE_CMD_RET_FAILED) {
+	if (!_jabber_send_buzz(js, username, &error)) {
 		purple_debug_error("jabber", "jabber_send_attention: jabber_cmd_buzz failed with error: %s\n", error ? error : "(NULL)");
+		g_free(error);
 		return FALSE;
-	} else {
-		return TRUE;
 	}
+
+	return TRUE;
 }
 
 


More information about the Commits mailing list