cpw.darkrain42.xmpp.scram: 7b57cce9: jabber: Fix that leak I mentioned (and f...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Fri Dec 4 01:32:05 EST 2009


-----------------------------------------------------------------
Revision: 7b57cce9601efeea3f4d2686c7961fa156703393
Ancestor: 3820a806a169960c1c5eed606d6ce431bb92a000
Author: darkrain42 at pidgin.im
Date: 2009-12-04T06:18:05
Branch: im.pidgin.cpw.darkrain42.xmpp.scram
URL: http://d.pidgin.im/viewmtn/revision/info/7b57cce9601efeea3f4d2686c7961fa156703393

Modified 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

ChangeLog: 

jabber: Fix that leak I mentioned (and fix a mistake where error/response weren't NULL-initialized)

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/auth.c	4e6fdfa14bb38a130dee2106af5c38772201ecdf
+++ libpurple/protocols/jabber/auth.c	c66ea15ffc15d38618b089e2e1db52852446f1ea
@@ -165,7 +165,7 @@ jabber_auth_start(JabberStream *js, xmln
 	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_auth_start(JabberStream *js, xmln
 		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 @@ jabber_auth_handle_challenge(JabberStrea
 
 	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_auth_handle_challenge(JabberStrea
 			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 @@ void jabber_auth_handle_success(JabberSt
 	}
 
 	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 @@ void jabber_auth_handle_success(JabberSt
 					msg ? msg : _("Server thinks authentication is complete, but client does not"));
 			return;
 		}
+
+		g_free(msg);
 	}
 
 	/*
@@ -473,11 +479,10 @@ void jabber_auth_handle_failure(JabberSt
 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 @@ void jabber_auth_handle_failure(JabberSt
 		}
 	}
 
-	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"));
============================================================
--- libpurple/protocols/jabber/auth.h	5de434da6e406659e76310786a8840555fff589c
+++ libpurple/protocols/jabber/auth.h	e2d06037617c6b145092f1545e894630bb79e757
@@ -38,10 +38,10 @@ struct _JabberSaslMech {
 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);
 };
 
============================================================
--- libpurple/protocols/jabber/auth_cyrus.c	640fdbe1b43ed6869fbab7f15a6353eccc8cdf67
+++ libpurple/protocols/jabber/auth_cyrus.c	7961f08b1d98e8bbb353c802d343d771e568832a
@@ -29,7 +29,7 @@ static JabberSaslState jabber_auth_start
 #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(JabberSt
 
 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
 }
 
 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 @@ jabber_auth_start_cyrus(JabberStream *js
 		*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 @@ jabber_cyrus_start(JabberStream *js, xml
 
 static JabberSaslState
 jabber_cyrus_start(JabberStream *js, xmlnode *mechanisms,
-                   xmlnode **reply, const char **error)
+                   xmlnode **reply, char **error)
 {
 	xmlnode *mechnode;
 
@@ -423,7 +424,7 @@ jabber_cyrus_handle_challenge(JabberStre
 
 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 @@ jabber_cyrus_handle_success(JabberStream
 
 static JabberSaslState
 jabber_cyrus_handle_success(JabberStream *js, xmlnode *packet,
-                            const char **error)
+                            char **error)
 {
 	const void *x;
 
@@ -502,7 +503,7 @@ jabber_cyrus_handle_success(JabberStream
 
 		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 @@ jabber_cyrus_handle_failure(JabberStream
 
 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) {
============================================================
--- libpurple/protocols/jabber/auth_digest_md5.c	54b9882edca5af04170c7b4402fd1e8b5d9f7833
+++ libpurple/protocols/jabber/auth_digest_md5.c	b71150d96183889e86e3eb285d1c636bc4c54952
@@ -32,7 +32,7 @@ digest_md5_start(JabberStream *js, xmlno
 
 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 @@ digest_md5_handle_challenge(JabberStream
 
 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 @@ digest_md5_handle_challenge(JabberStream
 	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 @@ digest_md5_handle_challenge(JabberStream
 			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 @@ digest_md5_handle_challenge(JabberStream
 			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("");
============================================================
--- libpurple/protocols/jabber/auth_plain.c	2bd068ef26d51259ac7adaed2443539c16753890
+++ libpurple/protocols/jabber/auth_plain.c	89fee941485f6311cbecacec9b3f1d9b87d68d85
@@ -81,7 +81,7 @@ static JabberSaslState
 }
 
 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;
============================================================
--- libpurple/protocols/jabber/auth_scram.c	0d682b79576e16f3d9b40622a61bc01ea258a015
+++ libpurple/protocols/jabber/auth_scram.c	586e9ec949cf578d39ffdb85c6f2e3e63c455f0a
@@ -349,7 +349,7 @@ static JabberSaslState
 }
 
 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 @@ scram_start(JabberStream *js, xmlnode *m
 
 	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 @@ scram_start(JabberStream *js, xmlnode *m
 	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
 }
 
 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 @@ scram_handle_challenge(JabberStream *js,
 		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 @@ scram_handle_challenge(JabberStream *js,
 		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 @@ scram_handle_challenge(JabberStream *js,
 		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
 }
 
 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 @@ scram_handle_success(JabberStream *js, x
 		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 @@ scram_handle_success(JabberStream *js, x
 	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 @@ scram_handle_success(JabberStream *js, x
 
 	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;
 	}
 


More information about the Commits mailing list