commit c6c7bd27b0de65e7204e372f0cd3dc505bb91c4c Author: Guido Berhoerster Date: Sun Nov 9 13:37:06 2014 +0100 Correctly determine the hostname Correct the changes introduced by commit 19e9cc2db222fde7f138de86f3cedcda4a4d4295, which assumed POSIX semantics without actually requesting it and then assumes that the maximum hostname length cannot be greater than 255 bytes if HOST_NAME_MAX is not defined. Due to this gethostname() can at least in theory write an unterminated string into display->hostname. The fix is to duplicate the string returned by g_get_host_name() which is always a null-terminated string. diff --git a/src/client.c b/src/client.c index dc00545..d012915 100644 --- a/src/client.c +++ b/src/client.c @@ -178,7 +178,7 @@ clientCreateTitleName (Client *c, gchar *name, gchar *hostname) screen_info = c->screen_info; display_info = screen_info->display_info; - if (strlen (hostname) && (display_info->hostname) && (g_ascii_strcasecmp (display_info->hostname, hostname))) + if (strlen (hostname) && (g_ascii_strcasecmp (display_info->hostname, hostname))) { /* TRANSLATORS: "(on %s)" is like "running on" the name of the other host */ title = g_strdup_printf (_("%s (on %s)"), name, hostname); diff --git a/src/display.c b/src/display.c index 3c2e7ba..40024e2 100644 --- a/src/display.c +++ b/src/display.c @@ -44,10 +44,6 @@ #include "client.h" #include "compositor.h" -#ifndef HOST_NAME_MAX -#define HOST_NAME_MAX 255 -#endif /* HOST_NAME_MAX */ - #ifndef CURSOR_ROOT #define CURSOR_ROOT XC_left_ptr #endif @@ -313,13 +309,7 @@ myDisplayInit (GdkDisplay *gdisplay) display->nb_screens = 0; display->current_time = CurrentTime; - display->hostname = g_new0 (gchar, (size_t) HOST_NAME_MAX + 1); - if (gethostname ((char *) display->hostname, HOST_NAME_MAX + 1)) - { - g_warning ("The display's hostname could not be determined."); - g_free (display->hostname); - display->hostname = NULL; - } + display->hostname = g_strdup (g_get_host_name ()); compositorInitDisplay (display);