summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Lantinga <slouken@libsdl.org>2012-02-20 20:50:38 -0500
committerSam Lantinga <slouken@libsdl.org>2012-02-20 20:50:38 -0500
commit12721f003559f1e774cae62bf579f216057ee2e0 (patch)
treeb9dc2f2bbff172e5f7ba5591233c3080e3bb53dd
parent31beff2f3a5cd3932f0d3562036ef7608276d166 (diff)
downloadsdl-12721f003559f1e774cae62bf579f216057ee2e0.tar.gz
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.
-rw-r--r--src/video/x11/SDL_x11video.c11
1 files 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));
}