From 032fc6a734516189e11b43e0b4680d15b62c5e66 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Wed, 31 Dec 2014 00:49:34 -0800 Subject: Only use results from GetWindowProperty if it returned success Since Xlib prior to 1.6 didn't always clear values on failure, don't assume they're safe to use unless we succeeded. Reported by Oracle Parfait 1.5.1: Error: Uninitialised memory (CWE 456) Possible access to uninitialised memory '&nPixels' at line 963 of src/parse.c in function 'put_pixel_on_root'. &nPixels allocated at line 953. Possible access to uninitialised memory '&retProp' at line 962 of src/parse.c in function 'put_pixel_on_root'. &retProp allocated at line 954. Signed-off-by: Alan Coopersmith --- src/parse.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/parse.c b/src/parse.c index 6ae9685..787e1b1 100644 --- a/src/parse.c +++ b/src/parse.c @@ -954,16 +954,15 @@ put_pixel_on_root(Pixel pixel) unsigned char*retProp; Pixel *pixelProp; pixelAtom = XInternAtom(dpy, "_MIT_PRIORITY_COLORS", True); - XGetWindowProperty(dpy, Scr->Root, pixelAtom, 0, 8192, - False, XA_CARDINAL, &retAtom, - &retFormat, &nPixels, &retAfter, - &retProp); - - pixelProp = (Pixel *) retProp; - for (i=0; i< nPixels; i++) - if (pixel == pixelProp[i]) - addPixel = 0; - + if (XGetWindowProperty(dpy, Scr->Root, pixelAtom, 0, 8192, + False, XA_CARDINAL, &retAtom, + &retFormat, &nPixels, &retAfter, + &retProp) == Success) { + pixelProp = (Pixel *) retProp; + for (i = 0; i < nPixels; i++) + if (pixel == pixelProp[i]) + addPixel = 0; + } if (addPixel) XChangeProperty (dpy, Scr->Root, _XA_MIT_PRIORITY_COLORS, XA_CARDINAL, 32, PropModeAppend, -- cgit v1.2.3