From 07ed63f865f6fef4c14711063534b73eb33e0cdb Mon Sep 17 00:00:00 2001 From: Egbert Eich Date: Thu, 19 May 2011 11:08:21 +0200 Subject: Fix SEGV if CreateColormapWindow() returns NULL. twm can segfault when it cannot collect attribute information on a window that has been destroyed before it got a chance to collect it's attributes. twm seems to assume that it is always able to collect this information and disregards the error if the function that attempts to collect it fails and CreateColormapWindow() returns NULL. If this happens correct number_cmap_windows to prevent a SEGV later on due to an incorrect setting. Signed-off-by: Egbert Eich --- src/add_window.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/add_window.c') diff --git a/src/add_window.c b/src/add_window.c index 8cf23c5..72aa0aa 100644 --- a/src/add_window.c +++ b/src/add_window.c @@ -1535,10 +1535,12 @@ FetchWmColormapWindows (TwmWindow *tmp) cwins = (ColormapWindow **) malloc(sizeof(ColormapWindow *)); if (XFindContext(dpy, tmp->w, ColormapContext, (caddr_t *)&cwins[0]) == - XCNOENT) + XCNOENT) { cwins[0] = CreateColormapWindow(tmp->w, (Bool) tmp->cmaps.number_cwins == 0, False); - else + if (cwins[0] == NULL) + number_cmap_windows = 0; + } else cwins[0]->refcnt++; } -- cgit v1.2.3