From e0f453603296e55ca2588b822b840d724d535893 Mon Sep 17 00:00:00 2001
From: Mamoru TASAKA <mtasaka@fedoraproject.org>
Date: Wed, 20 Jun 2018 18:21:45 +0900
Subject: [PATCH] xscreensaver-getimage: avoid substitution to NULL pointer

When user chooses not to use any image resource on "Image Manupulation"
in xscreensaver-demo, xscreensaver-getimage program tries to do
GRAB_BARS mode, then calls colorbars() function and it causes segfault
like:

#0  0x000055555556227a in minixpm_to_ximage (dpy=dpy@entry=0x555555788b10, visual=visual@entry=0x555555795dd0, colormap=colormap@entry=32, depth=depth@entry=24, transparent_color=<optimized out>, data=<optimized out>, data@entry=0x555555775e80 <logo_180_xpm>, width_ret=0x7fffffffcb30, height_ret=0x7fffffffcb34, pixels_ret=0x0, npixels_ret=0x0, mask_ret=0x7fffffffcb38) at ../../utils/minixpm.c:248
#1  0x0000555555561b93 in xscreensaver_logo (screen=screen@entry=0x55555578a1d0, visual=visual@entry=0x555555795dd0, drawable=drawable@entry=707, cmap=cmap@entry=32, background_color=<optimized out>, pixels_ret=pixels_ret@entry=0x0, npixels_ret=0x0, mask_ret=0x7fffffffccf0, big_p=1) at ../../utils/logo.c:49
#2  0x000055555555ab5f in colorbars (cmap=32, drawable=707, visual=0x555555795dd0, screen=0x55555578a1d0) at ../../driver/xscreensaver-getimage.c:319
#3  0x000055555555ab5f in get_image (screen=<optimized out>, file=<optimized out>, dir=<optimized out>, image_p=<optimized out>, video_p=<optimized out>, desk_p=<optimized out>, verbose_p=0, drawable=707, window=707) at ../../driver/xscreensaver-getimage.c:1697
#4  0x000055555555ab5f in main (argc=<optimized out>, argv=<optimized out>) at ../../driver/xscreensaver-getimage.c:1994
#5  0x00007ffff54d818b in __libc_start_main (main=0x55555555a4f0 <main>, argc=2, argv=0x7fffffffd428, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffd418)
    at ../csu/libc-start.c:308

This patch avoids NULL pointer accessment, as xscreensaver 5.38 was doing
in (5.38) draw_colorbars() function.
---
 driver/xscreensaver-getimage.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/driver/xscreensaver-getimage.c b/driver/xscreensaver-getimage.c
index b9715ae..6cf5c99 100644
--- a/driver/xscreensaver-getimage.c
+++ b/driver/xscreensaver-getimage.c
@@ -316,9 +316,11 @@ static void
 colorbars (Screen *screen, Visual *visual, Drawable drawable, Colormap cmap)
 {
   Pixmap mask = 0;
+  unsigned long *pixels; /* ignored - unfreed */
+  int npixels;
   Pixmap logo = xscreensaver_logo (screen, visual, drawable, cmap,
                                    BlackPixelOfScreen (screen),
-                                   0, 0, &mask, True);
+                                   &pixels, &npixels, &mask, True);
   draw_colorbars (screen, visual, drawable, cmap, 0, 0, 0, 0, logo, mask);
   XFreePixmap (DisplayOfScreen (screen), logo);
   XFreePixmap (DisplayOfScreen (screen), mask);
-- 
2.17.1

