pidgin: a1515f71: Escape IRC hostnames beginning with : in...

elb at pidgin.im elb at pidgin.im
Fri Jul 25 12:40:52 EDT 2008


-----------------------------------------------------------------
Revision: a1515f71238597d861299c4a998b98967c1d6ef9
Ancestor: 35ff3232ee23ba378088f681bc89be82f161dce7
Author: elb at pidgin.im
Date: 2008-07-25T16:33:24
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/a1515f71238597d861299c4a998b98967c1d6ef9

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

ChangeLog: 

Escape IRC hostnames beginning with : in the USER command.  This
should prevent IPv6 addresses (such as ::v4_addr or ::1) from bungling
the USER command.

Fixes #6146

-------------- next part --------------
============================================================
--- libpurple/protocols/irc/irc.c	9a2f7b26ea21ff1002cbab7b3b708448db60a880
+++ libpurple/protocols/irc/irc.c	afe1bb6f873de92dd1aca7288273ccc146b3b29e
@@ -360,7 +360,8 @@ static gboolean do_login(PurpleConnectio
 
 static gboolean do_login(PurpleConnection *gc) {
 	char *buf, *tmp = NULL;
-	const char *hostname;
+	char *hostname, *server;
+	const char *hosttmp;
 	const char *username, *realname;
 	struct irc_conn *irc = gc->proto_data;
 	const char *pass = purple_connection_get_password(gc);
@@ -374,7 +375,6 @@ static gboolean do_login(PurpleConnectio
 		g_free(buf);
 	}
 
-	hostname = purple_get_host_name();
 	realname = purple_account_get_string(irc->account, "realname", "");
 	username = purple_account_get_string(irc->account, "username", "");
 
@@ -389,9 +389,29 @@ static gboolean do_login(PurpleConnectio
 		}
 	}
 
-	buf = irc_format(irc, "vvvv:", "USER", tmp ? tmp : username, hostname, irc->server,
-			      strlen(realname) ? realname : IRC_DEFAULT_ALIAS);
+	hosttmp = purple_get_host_name();
+	if (*hosttmp == ':') {
+		/* This is either an IPv6 address, or something which
+		 * doesn't belong here.  Either way, we need to escape
+		 * it. */
+		hostname = g_strdup_printf("0%s", hosttmp);
+	} else {
+		/* Ugly, I know. */
+		hostname = g_strdup(hosttmp);
+	}
+
+	if (*irc->server == ':') {
+		/* Same as hostname, above. */
+		server = g_strdup_printf("0%s", irc->server);
+	} else {
+		server = g_strdup(irc->server);
+	}
+
+	buf = irc_format(irc, "vvvv:", "USER", tmp ? tmp : username, hostname, server,
+	                 strlen(realname) ? realname : IRC_DEFAULT_ALIAS);
 	g_free(tmp);
+	g_free(hostname);
+	g_free(server);
 	if (irc_send(irc, buf) < 0) {
 		g_free(buf);
 		return FALSE;


More information about the Commits mailing list