From 7ced7366971148aa44c4e965aa02c2158222871e Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 20 Feb 2012 20:50:38 -0500 Subject: [PATCH] Fixed bug 1427 - integer passed to XChangeProperty() causes crash Julian Coleman 2012-02-20 06:51:12 PST In src/video/x11/SDL_x11video.c, the result of getpid(), i.e., a pid_t is passed to: XChangeProperty(..., 32, ...) However, using 32 here means that Xlib treats the value as a long, and pid_t is an int. So, we get a bus error inside Xlib. The fix is to make sure that anything passed to XChangeProperty() is aligned correctly. Note, that the other calls to XChangeProperty() pass long values here. The proposed patch makes a union of the pid_t return type from getpid() and a dummy long. This has been tested to fix the bus error crash on NetBSD/sparc64. --- src/video/x11/SDL_x11video.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c index f7d80732c..afdaa658e 100644 --- a/src/video/x11/SDL_x11video.c +++ b/src/video/x11/SDL_x11video.c @@ -418,16 +418,21 @@ static void create_aux_windows(_THIS) } { - pid_t pid = getpid(); + union align_pid { + pid_t pid; + long dummy; + } a_pid; char hostname[256]; + + a_pid.pid = getpid(); - if (pid > 0 && gethostname(hostname, sizeof(hostname)) > -1) { + if (a_pid.pid > 0 && gethostname(hostname, sizeof(hostname)) > -1) { Atom _NET_WM_PID = XInternAtom(SDL_Display, "_NET_WM_PID", False); Atom WM_CLIENT_MACHINE = XInternAtom(SDL_Display, "WM_CLIENT_MACHINE", False); hostname[sizeof(hostname)-1] = '\0'; XChangeProperty(SDL_Display, WMwindow, _NET_WM_PID, XA_CARDINAL, 32, - PropModeReplace, (unsigned char *)&pid, 1); + PropModeReplace, (unsigned char *)&(a_pid.pid), 1); XChangeProperty(SDL_Display, WMwindow, WM_CLIENT_MACHINE, XA_STRING, 8, PropModeReplace, (unsigned char *)hostname, SDL_strlen(hostname)); }