me likes this better, References #5565

Sat, 29 Nov 2008 01:52:36 +0000

author
Ka-Hing Cheung <khc@pidgin.im>
date
Sat, 29 Nov 2008 01:52:36 +0000
changeset 24824
2da1f210b9a2
parent 24823
7ecb44befa96
child 24825
f928f0d7ac2a
child 24826
1ce0a7a3ab84

me likes this better, References #5565

libpurple/protocols/jabber/jabber.c file | annotate | diff | comparison | revisions
--- a/libpurple/protocols/jabber/jabber.c	Sat Nov 29 01:35:02 2008 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Sat Nov 29 01:52:36 2008 +0000
@@ -150,14 +150,21 @@
 	char hostname[256]; /* current hostname */
 
 	/* Empty resource == don't send any */
-	if (strlen(input) == 0)
+	if (*input == '\0' || strstr(input, "__HOSTNAME__") == NULL)
 		return NULL;
 
 	/* Replace __HOSTNAME__ with hostname */
-	if (gethostname(hostname, sizeof(hostname))) {
-		purple_debug_warning("jabber", "gethostname() failed -- is your hostname set?");
+	if (gethostname(hostname, sizeof(hostname) - 1)) {
+		purple_debug_warning("jabber", "gethostname: %s\n", g_strerror(errno));
+		/* according to glibc doc, the only time an error is returned
+		   is if the hostname is longer than the buffer, in which case
+		   glibc 2.2+ would still fill the buffer with partial
+		   hostname, so maybe we want to detect that and use it
+		   instead
+		*/
 		strcpy(hostname, "localhost");
 	}
+	hostname[sizeof(hostname) - 1] = '\0';
 
 	return purple_strreplace(input, "__HOSTNAME__", hostname);
 }

mercurial