From 2c9941c3033240322f96da07c91ba91cb35daafb Mon Sep 17 00:00:00 2001 From: Alistair Buxton Date: Wed, 5 Nov 2014 19:36:11 +0000 Subject: [PATCH] Determine the maximum host name length correctly. The actual limit on Linux is 64 characters, and on BSD it is 255 characters. The limit is defined in HOST_NAME_MAX on Posic operating systems, so use that definition instead of the one hardcoded into Xfwm, and print a warning if it still fails. Too long hostnames would previously cause the hostname to be set to null, which would cause a segfault when terminating a client. This patch also adds a null check to that function. --- src/client.c | 2 +- src/display.c | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/client.c b/src/client.c index 60430a8..dc00545 100644 --- a/src/client.c +++ b/src/client.c @@ -2573,7 +2573,7 @@ clientTerminate (Client *c) screen_info = c->screen_info; display_info = screen_info->display_info; - if ((c->hostname) && (c->pid > 0)) + if ((c->hostname) && (display_info->hostname) && (c->pid > 0)) { if (!strcmp (display_info->hostname, c->hostname)) { diff --git a/src/display.c b/src/display.c index 00318d5..3c2e7ba 100644 --- a/src/display.c +++ b/src/display.c @@ -44,9 +44,9 @@ #include "client.h" #include "compositor.h" -#ifndef MAX_HOSTNAME_LENGTH -#define MAX_HOSTNAME_LENGTH 32 -#endif /* MAX_HOSTNAME_LENGTH */ +#ifndef HOST_NAME_MAX +#define HOST_NAME_MAX 255 +#endif /* HOST_NAME_MAX */ #ifndef CURSOR_ROOT #define CURSOR_ROOT XC_left_ptr @@ -313,9 +313,10 @@ myDisplayInit (GdkDisplay *gdisplay) display->nb_screens = 0; display->current_time = CurrentTime; - display->hostname = g_new0 (gchar, (size_t) MAX_HOSTNAME_LENGTH); - if (gethostname ((char *) display->hostname, MAX_HOSTNAME_LENGTH - 1)) + 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; } -- 1.9.1