From fbbb1350d7f210ec52c06c2b1e020c25a00d9958 Mon Sep 17 00:00:00 2001 From: Ethan Blanton Date: Mon, 3 Sep 2007 23:15:11 +0000 Subject: 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 --- libpurple/protocols/irc/irc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'libpurple/protocols/irc/irc.c') diff --git a/libpurple/protocols/irc/irc.c b/libpurple/protocols/irc/irc.c index a783ae0fbc..731f38c53d 100644 --- a/libpurple/protocols/irc/irc.c +++ b/libpurple/protocols/irc/irc.c @@ -347,6 +347,7 @@ static gboolean do_login(PurpleConnection *gc) { 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 @@ static gboolean do_login(PurpleConnection *gc) { } - 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", ""); -- cgit v1.2.1