[Xfce4-commits] [xfce/xfwm4] 01/01: Extremely paranoid hostname lookup (bug #11289)
noreply at xfce.org
noreply at xfce.org
Sun Nov 30 17:00:07 CET 2014
This is an automated email from the git hooks/post-receive script.
ochosi pushed a commit to branch master
in repository xfce/xfwm4.
commit 85dffa9adab8bc2c5d11550bdbc8235291802d4e
Author: Alistair Buxton <a.j.buxton at gmail.com>
Date: Fri Nov 28 09:27:11 2014 +0000
Extremely paranoid hostname lookup (bug #11289)
Get the hostname into a large temporary array first, then g_strdup it to
avoid memory wastage. The temporary array is allocated with g_new0 to ensure
it doesn't contain garbage if gethostname() does nothing. The last element
is always set to null in case gethostname() overruns the buffer and doesn't
return an error.
Signed-off-by: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
---
src/display.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/display.c b/src/display.c
index 3c2e7ba..42b8bfe 100644
--- a/src/display.c
+++ b/src/display.c
@@ -44,9 +44,9 @@
#include "client.h"
#include "compositor.h"
-#ifndef HOST_NAME_MAX
-#define HOST_NAME_MAX 255
-#endif /* HOST_NAME_MAX */
+#ifndef MAX_HOSTNAME_LENGTH
+#define MAX_HOSTNAME_LENGTH 512
+#endif /* MAX_HOSTNAME_LENGTH */
#ifndef CURSOR_ROOT
#define CURSOR_ROOT XC_left_ptr
@@ -198,6 +198,7 @@ myDisplayInit (GdkDisplay *gdisplay)
DisplayInfo *display;
int major, minor;
int dummy;
+ gchar *hostnametmp;
display = g_new0 (DisplayInfo, 1);
@@ -313,13 +314,16 @@ 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))
+ hostnametmp = g_new0 (gchar, (size_t) MAX_HOSTNAME_LENGTH + 1);
+ if (gethostname ((char *) hostnametmp, MAX_HOSTNAME_LENGTH))
{
g_warning ("The display's hostname could not be determined.");
- g_free (display->hostname);
display->hostname = NULL;
+ } else {
+ hostnametmp[MAX_HOSTNAME_LENGTH] = '\0';
+ display->hostname = g_strdup(hostnametmp);
}
+ g_free (hostnametmp);
compositorInitDisplay (display);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list