Skip to content
Permalink
Browse files

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.
  • Loading branch information
slouken committed Feb 21, 2012
1 parent d836339 commit 7ced7366971148aa44c4e965aa02c2158222871e
Showing with 8 additions and 3 deletions.
  1. +8 −3 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));
}

0 comments on commit 7ced736

Please sign in to comment.