changeset 22228:6337a8fd7784

From the gethostname() man page: "In case the null-terminated hostname does not fit, no error is returned, but the hostname is truncated. It is unspecified whether the truncated hostname will be null-terminated."
author Mark Doliner <mark@kingant.net>
date Mon, 28 Jan 2008 05:31:28 +0000
parents da9179374c50
children ae5917260eac
files libpurple/protocols/bonjour/bonjour.c
diffstat 1 files changed, 2 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/bonjour/bonjour.c	Mon Jan 28 04:10:59 2008 +0000
+++ b/libpurple/protocols/bonjour/bonjour.c	Mon Jan 28 05:31:28 2008 +0000
@@ -673,11 +673,12 @@
 
 	/* Try to figure out a good host name to use */
 	/* TODO: Avoid 'localhost,' if possible */
-	if (gethostname(hostname, 255) != 0) {
+	if (gethostname(hostname, sizeof(hostname)) != 0) {
 		purple_debug_warning("bonjour", "Error when getting host name: %s.  Using \"localhost.\"\n",
 				g_strerror(errno));
 		strcpy(hostname, "localhost");
 	}
+	hostname[sizeof(hostname) - 1] = '\0';
 	default_hostname = g_strdup(hostname);
 }