comparison libpurple/protocols/irc/irc.c @ 23638:1b7dea5ce0cd

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
author Ethan Blanton <elb@pidgin.im>
date Fri, 25 Jul 2008 16:33:24 +0000
parents 399975ad001c
children aac5753e2528 e81f0d1966db
comparison
equal deleted inserted replaced
23637:66497a2bc489 23638:1b7dea5ce0cd
358 } 358 }
359 } 359 }
360 360
361 static gboolean do_login(PurpleConnection *gc) { 361 static gboolean do_login(PurpleConnection *gc) {
362 char *buf, *tmp = NULL; 362 char *buf, *tmp = NULL;
363 const char *hostname; 363 char *hostname, *server;
364 const char *hosttmp;
364 const char *username, *realname; 365 const char *username, *realname;
365 struct irc_conn *irc = gc->proto_data; 366 struct irc_conn *irc = gc->proto_data;
366 const char *pass = purple_connection_get_password(gc); 367 const char *pass = purple_connection_get_password(gc);
367 368
368 if (pass && *pass) { 369 if (pass && *pass) {
372 return FALSE; 373 return FALSE;
373 } 374 }
374 g_free(buf); 375 g_free(buf);
375 } 376 }
376 377
377 hostname = purple_get_host_name();
378 realname = purple_account_get_string(irc->account, "realname", ""); 378 realname = purple_account_get_string(irc->account, "realname", "");
379 username = purple_account_get_string(irc->account, "username", ""); 379 username = purple_account_get_string(irc->account, "username", "");
380 380
381 if (username == NULL || *username == '\0') { 381 if (username == NULL || *username == '\0') {
382 username = g_get_user_name(); 382 username = g_get_user_name();
387 while ((buf = strchr(tmp, ' ')) != NULL) { 387 while ((buf = strchr(tmp, ' ')) != NULL) {
388 *buf = '_'; 388 *buf = '_';
389 } 389 }
390 } 390 }
391 391
392 buf = irc_format(irc, "vvvv:", "USER", tmp ? tmp : username, hostname, irc->server, 392 hosttmp = purple_get_host_name();
393 strlen(realname) ? realname : IRC_DEFAULT_ALIAS); 393 if (*hosttmp == ':') {
394 /* This is either an IPv6 address, or something which
395 * doesn't belong here. Either way, we need to escape
396 * it. */
397 hostname = g_strdup_printf("0%s", hosttmp);
398 } else {
399 /* Ugly, I know. */
400 hostname = g_strdup(hosttmp);
401 }
402
403 if (*irc->server == ':') {
404 /* Same as hostname, above. */
405 server = g_strdup_printf("0%s", irc->server);
406 } else {
407 server = g_strdup(irc->server);
408 }
409
410 buf = irc_format(irc, "vvvv:", "USER", tmp ? tmp : username, hostname, server,
411 strlen(realname) ? realname : IRC_DEFAULT_ALIAS);
394 g_free(tmp); 412 g_free(tmp);
413 g_free(hostname);
414 g_free(server);
395 if (irc_send(irc, buf) < 0) { 415 if (irc_send(irc, buf) < 0) {
396 g_free(buf); 416 g_free(buf);
397 return FALSE; 417 return FALSE;
398 } 418 }
399 g_free(buf); 419 g_free(buf);