changeset 28754:b94fd073187c

jabber: Fix that leak I mentioned (and fix a mistake where error/response weren't NULL-initialized)
author Paul Aurich <paul@darkrain42.org>
date Fri, 04 Dec 2009 06:18:05 +0000
parents 8a5252630857
children fb550b27c6d8
files libpurple/protocols/jabber/auth.c libpurple/protocols/jabber/auth.h libpurple/protocols/jabber/auth_cyrus.c libpurple/protocols/jabber/auth_digest_md5.c libpurple/protocols/jabber/auth_plain.c libpurple/protocols/jabber/auth_scram.c
diffstat 6 files changed, 46 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/auth.c	Fri Dec 04 06:04:18 2009 +0000
+++ b/libpurple/protocols/jabber/auth.c	Fri Dec 04 06:18:05 2009 +0000
@@ -165,7 +165,7 @@
 	xmlnode *response = NULL;
 	xmlnode *mechs, *mechnode;
 	JabberSaslState state;
-	const char *msg = NULL;
+	char *msg = NULL;
 
 	if(js->registration) {
 		jabber_register_start(js);
@@ -225,6 +225,8 @@
 		jabber_send(js, response);
 		xmlnode_free(response);
 	}
+
+	g_free(msg);
 }
 
 static void auth_old_result_cb(JabberStream *js, const char *from,
@@ -420,7 +422,7 @@
 
 	if (js->auth_mech && js->auth_mech->handle_challenge) {
 		xmlnode *response = NULL;
-		const char *msg = NULL;
+		char *msg = NULL;
 		JabberSaslState state = js->auth_mech->handle_challenge(js, packet, &response, &msg);
 		if (state == JABBER_SASL_STATE_FAIL) {
 			purple_connection_error_reason(js->gc,
@@ -430,6 +432,8 @@
 			jabber_send(js, response);
 			xmlnode_free(response);
 		}
+
+		g_free(msg);
 	} else
 		purple_debug_warning("jabber", "Received unexpected (and unhandled) <challenge/>\n");
 }
@@ -446,7 +450,7 @@
 	}
 
 	if (js->auth_mech && js->auth_mech->handle_success) {
-		const char *msg = NULL;
+		char *msg = NULL;
 		JabberSaslState state = js->auth_mech->handle_success(js, packet, &msg);
 
 		if (state == JABBER_SASL_STATE_FAIL) {
@@ -460,6 +464,8 @@
 					msg ? msg : _("Server thinks authentication is complete, but client does not"));
 			return;
 		}
+
+		g_free(msg);
 	}
 
 	/*
@@ -473,11 +479,10 @@
 void jabber_auth_handle_failure(JabberStream *js, xmlnode *packet)
 {
 	PurpleConnectionError reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
-	char *msg;
+	char *msg = NULL;
 
 	if (js->auth_mech && js->auth_mech->handle_failure) {
 		xmlnode *stanza = NULL;
-		const char *msg = NULL;
 		JabberSaslState state = js->auth_mech->handle_failure(js, packet, &stanza, &msg);
 
 		if (state != JABBER_SASL_STATE_FAIL && stanza) {
@@ -487,8 +492,10 @@
 		}
 	}
 
-	msg = jabber_parse_error(js, packet, &reason);
-	if(!msg) {
+	if (!msg)
+		msg = jabber_parse_error(js, packet, &reason);
+
+	if (!msg) {
 		purple_connection_error_reason(js->gc,
 			PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
 			_("Invalid response from server"));
--- a/libpurple/protocols/jabber/auth.h	Fri Dec 04 06:04:18 2009 +0000
+++ b/libpurple/protocols/jabber/auth.h	Fri Dec 04 06:18:05 2009 +0000
@@ -38,10 +38,10 @@
 struct _JabberSaslMech {
 	gint8 priority; /* Higher priority will be tried before lower priority */
 	const gchar *name;
-	JabberSaslState (*start)(JabberStream *js, xmlnode *mechanisms, xmlnode **reply, const char **msg);
-	JabberSaslState (*handle_challenge)(JabberStream *js, xmlnode *packet, xmlnode **reply, const char **msg);
-	JabberSaslState (*handle_success)(JabberStream *js, xmlnode *packet, const char **msg);
-	JabberSaslState (*handle_failure)(JabberStream *js, xmlnode *packet, xmlnode **reply, const char **msg);
+	JabberSaslState (*start)(JabberStream *js, xmlnode *mechanisms, xmlnode **reply, char **msg);
+	JabberSaslState (*handle_challenge)(JabberStream *js, xmlnode *packet, xmlnode **reply, char **msg);
+	JabberSaslState (*handle_success)(JabberStream *js, xmlnode *packet, char **msg);
+	JabberSaslState (*handle_failure)(JabberStream *js, xmlnode *packet, xmlnode **reply, char **msg);
 	void (*dispose)(JabberStream *js);
 };
 
--- a/libpurple/protocols/jabber/auth_cyrus.c	Fri Dec 04 06:04:18 2009 +0000
+++ b/libpurple/protocols/jabber/auth_cyrus.c	Fri Dec 04 06:18:05 2009 +0000
@@ -29,7 +29,7 @@
 #include "jabber.h"
 
 static JabberSaslState jabber_auth_start_cyrus(JabberStream *js, xmlnode **reply,
-                                               const char **error);
+                                               char **error);
 static void jabber_sasl_build_callbacks(JabberStream *);
 
 static void disallow_plaintext_auth(PurpleAccount *account)
@@ -41,14 +41,15 @@
 
 static void start_cyrus_wrapper(JabberStream *js)
 {
-	const char *error;
-	xmlnode *response;
+	char *error = NULL;
+	xmlnode *response = NULL;
 	JabberSaslState state = jabber_auth_start_cyrus(js, &response, &error);
 
 	if (state == JABBER_SASL_STATE_FAIL) {
 		purple_connection_error_reason(js->gc,
 				PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE,
 				error);
+		g_free(error);
 	} else if (response) {
 		jabber_send(js, response);
 		xmlnode_free(response);
@@ -180,7 +181,7 @@
 }
 
 static JabberSaslState
-jabber_auth_start_cyrus(JabberStream *js, xmlnode **reply, const char **error)
+jabber_auth_start_cyrus(JabberStream *js, xmlnode **reply, char **error)
 {
 	PurpleAccount *account;
 	const char *clientout = NULL;
@@ -329,7 +330,7 @@
 		*reply = auth;
 		return JABBER_SASL_STATE_CONTINUE;
 	} else {
-		*error = _("SASL authentication failed");
+		*error = g_strdup(_("SASL authentication failed"));
 		return JABBER_SASL_STATE_FAIL;
 	}
 }
@@ -387,7 +388,7 @@
 
 static JabberSaslState
 jabber_cyrus_start(JabberStream *js, xmlnode *mechanisms,
-                   xmlnode **reply, const char **error)
+                   xmlnode **reply, char **error)
 {
 	xmlnode *mechnode;
 
@@ -423,7 +424,7 @@
 
 static JabberSaslState
 jabber_cyrus_handle_challenge(JabberStream *js, xmlnode *packet,
-                              xmlnode **reply, const char **error)
+                              xmlnode **reply, char **error)
 {
 	char *enc_in = xmlnode_get_data(packet);
 	unsigned char *dec_in;
@@ -478,7 +479,7 @@
 
 static JabberSaslState
 jabber_cyrus_handle_success(JabberStream *js, xmlnode *packet,
-                            const char **error)
+                            char **error)
 {
 	const void *x;
 
@@ -502,7 +503,7 @@
 
 		if (js->sasl_state != SASL_OK) {
 			/* This should never happen! */
-			*error = _("Invalid response from server");
+			*error = g_strdup(_("Invalid response from server"));
 			g_return_val_if_reached(JABBER_SASL_STATE_FAIL);
 		}
 	}
@@ -521,7 +522,7 @@
 
 static JabberSaslState
 jabber_cyrus_handle_failure(JabberStream *js, xmlnode *packet,
-                            xmlnode **reply, const char **error)
+                            xmlnode **reply, char **error)
 {
 	if (js->auth_fail_count++ < 5) {
 		if (js->current_mech && *js->current_mech) {
--- a/libpurple/protocols/jabber/auth_digest_md5.c	Fri Dec 04 06:04:18 2009 +0000
+++ b/libpurple/protocols/jabber/auth_digest_md5.c	Fri Dec 04 06:18:05 2009 +0000
@@ -32,7 +32,7 @@
 
 static JabberSaslState
 digest_md5_start(JabberStream *js, xmlnode *packet, xmlnode **response,
-                 const char **msg)
+                 char **error)
 {
 	xmlnode *auth = xmlnode_new("auth");
 	xmlnode_set_namespace(auth, NS_XMPP_SASL);
@@ -166,7 +166,7 @@
 
 static JabberSaslState
 digest_md5_handle_challenge(JabberStream *js, xmlnode *packet,
-                            xmlnode **response, const char **msg)
+                            xmlnode **response, char **msg)
 {
 	xmlnode *reply = NULL;
 	char *enc_in = xmlnode_get_data(packet);
@@ -176,7 +176,7 @@
 	JabberSaslState state = JABBER_SASL_STATE_CONTINUE;
 
 	if (!enc_in) {
-		*msg = _("Invalid response from server");
+		*msg = g_strdup(_("Invalid response from server"));
 		return JABBER_SASL_STATE_FAIL;
 	}
 
@@ -193,7 +193,7 @@
 			reply = xmlnode_new("response");
 			xmlnode_set_namespace(reply, NS_XMPP_SASL);
 		} else {
-			*msg = _("Invalid challenge from server");
+			*msg = g_strdup(_("Invalid challenge from server"));
 			state = JABBER_SASL_STATE_FAIL;
 		}
 		g_free(js->expected_rspauth);
@@ -218,7 +218,7 @@
 			realm = js->user->domain;
 
 		if (nonce == NULL || realm == NULL) {
-			*msg = _("Invalid challenge from server");
+			*msg = g_strdup(_("Invalid challenge from server"));
 			state = JABBER_SASL_STATE_FAIL;
 		} else {
 			GString *response = g_string_new("");
--- a/libpurple/protocols/jabber/auth_plain.c	Fri Dec 04 06:04:18 2009 +0000
+++ b/libpurple/protocols/jabber/auth_plain.c	Fri Dec 04 06:18:05 2009 +0000
@@ -81,7 +81,7 @@
 }
 
 static JabberSaslState
-jabber_plain_start(JabberStream *js, xmlnode *packet, xmlnode **response, const char **error)
+jabber_plain_start(JabberStream *js, xmlnode *packet, xmlnode **response, char **error)
 {
 	PurpleAccount *account = purple_connection_get_account(js->gc);
 	char *msg;
--- a/libpurple/protocols/jabber/auth_scram.c	Fri Dec 04 06:04:18 2009 +0000
+++ b/libpurple/protocols/jabber/auth_scram.c	Fri Dec 04 06:18:05 2009 +0000
@@ -349,7 +349,7 @@
 }
 
 static JabberSaslState
-scram_start(JabberStream *js, xmlnode *mechanisms, xmlnode **out, const char **error)
+scram_start(JabberStream *js, xmlnode *mechanisms, xmlnode **out, char **error)
 {
 	xmlnode *reply;
 	JabberScramData *data;
@@ -363,7 +363,7 @@
 
 	prepped_node = jabber_saslprep(js->user->node);
 	if (!prepped_node) {
-		*error = _("Unable to canonicalize username");
+		*error = g_strdup(_("Unable to canonicalize username"));
 		return JABBER_SASL_STATE_FAIL;
 	}
 
@@ -374,7 +374,7 @@
 	prepped_pass = jabber_saslprep(purple_connection_get_password(js->gc));
 	if (!prepped_pass) {
 		g_free(prepped_node);
-		*error = _("Unable to canonicalize password");
+		*error = g_strdup(_("Unable to canonicalize password"));
 		return JABBER_SASL_STATE_FAIL;
 	}
 
@@ -415,7 +415,7 @@
 }
 
 static JabberSaslState
-scram_handle_challenge(JabberStream *js, xmlnode *challenge, xmlnode **out, const char **error)
+scram_handle_challenge(JabberStream *js, xmlnode *challenge, xmlnode **out, char **error)
 {
 	JabberScramData *data = js->auth_mech_data;
 	xmlnode *reply;
@@ -429,7 +429,7 @@
 		reply = xmlnode_new("abort");
 		xmlnode_set_namespace(reply, NS_XMPP_SASL);
 		data->step = -1;
-		*error = _("Invalid challenge from server");
+		*error = g_strdup(_("Invalid challenge from server"));
 		goto out;
 	}
 
@@ -440,7 +440,7 @@
 		reply = xmlnode_new("abort");
 		xmlnode_set_namespace(reply, NS_XMPP_SASL);
 		data->step = -1;
-		*error = _("Malicious challenge from server");
+		*error = g_strdup(_("Malicious challenge from server"));
 		goto out;
 	}
 
@@ -450,7 +450,7 @@
 		reply = xmlnode_new("abort");
 		xmlnode_set_namespace(reply, NS_XMPP_SASL);
 		data->step = -1;
-		*error = _("Invalid challenge from server");
+		*error = g_strdup(_("Invalid challenge from server"));
 		goto out;
 	}
 
@@ -476,7 +476,7 @@
 }
 
 static JabberSaslState
-scram_handle_success(JabberStream *js, xmlnode *packet, const char **error)
+scram_handle_success(JabberStream *js, xmlnode *packet, char **error)
 {
 	JabberScramData *data = js->auth_mech_data;
 	char *enc_in, *dec_in;
@@ -490,7 +490,7 @@
 		return JABBER_SASL_STATE_OK;
 
 	if (data->step != 2) {
-		*error = _("Unexpected response from server");
+		*error = g_strdup(_("Unexpected response from server"));
 		return JABBER_SASL_STATE_FAIL;
 	}
 
@@ -499,7 +499,7 @@
 	if (!dec_in || len != strlen(dec_in)) {
 		/* Danger afoot; SCRAM shouldn't contain NUL bytes */
 		g_free(dec_in);
-		*error = _("Invalid challenge from server");
+		*error = g_strdup(_("Invalid challenge from server"));
 		return JABBER_SASL_STATE_FAIL;
 	}
 
@@ -507,7 +507,7 @@
 
 	if (!jabber_scram_feed_parser(data, dec_in, &dec_out) || dec_out != NULL) {
 		g_free(dec_out);
-		*error = _("Invalid challenge from server");
+		*error = g_strdup(_("Invalid challenge from server"));
 		return JABBER_SASL_STATE_FAIL;
 	}