Skip to content

Commit

Permalink
Fixed bug 1427 - integer passed to XChangeProperty() causes crash
Browse files Browse the repository at this point in the history
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 7ced736
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/video/x11/SDL_x11video.c
Expand Up @@ -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));
}
Expand Down

0 comments on commit 7ced736

Please sign in to comment.