# HG changeset patch # User Ethan Blanton # Date 1188861311 0 # Node ID cab5dd8da484a0a45e6b022d373d1d3de4c1086e # Parent b4a4a0a09e0ae04120b4f29cf13bc1b43314cea5 Handle the case where gethostname() fails or returns a null hostname. This really shouldn't happen on a properly configured system, but its failure also should not prevent us from being able to log into IRC. Fixes #2932 diff -r b4a4a0a09e0a -r cab5dd8da484 libpurple/protocols/irc/irc.c --- a/libpurple/protocols/irc/irc.c Mon Sep 03 22:04:47 2007 +0000 +++ b/libpurple/protocols/irc/irc.c Mon Sep 03 23:15:11 2007 +0000 @@ -347,6 +347,7 @@ const char *username, *realname; struct irc_conn *irc = gc->proto_data; const char *pass = purple_connection_get_password(gc); + int ret; if (pass && *pass) { buf = irc_format(irc, "vv", "PASS", pass); @@ -359,8 +360,12 @@ } - gethostname(hostname, sizeof(hostname)); + ret = gethostname(hostname, sizeof(hostname)); hostname[sizeof(hostname) - 1] = '\0'; + if (ret < 0 || hostname[0] == '\0') { + purple_debug_warning("irc", "gethostname() failed -- is your hostname set?"); + strcpy(hostname, "localhost"); + } realname = purple_account_get_string(irc->account, "realname", ""); username = purple_account_get_string(irc->account, "username", "");