[PATCH:transset] Only use property pointer if XGetWindowProperty returns success

Alan Coopersmith alan.coopersmith at oracle.com
Sat Jan 3 14:29:45 PST 2015


In Xlib versions prior to 1.6, if XGetWindowProperty returns a failure,
it didn't always set the property pointer to NULL, and could leave it
uninitialized.

Reported by Oracle Parfait 1.5.1:
Error: Uninitialised memory (CWE 456)
   Possible access to uninitialised memory '&data'
        at line 298 of transSet.c in function 'main'.
          &data allocated at line 154.
        at line 299 of transSet.c in function 'main'.
          &data allocated at line 154.
        at line 300 of transSet.c in function 'main'.
          &data allocated at line 154.

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 transSet.c |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/transSet.c b/transSet.c
index 9938e79..04c40e4 100644
--- a/transSet.c
+++ b/transSet.c
@@ -291,11 +291,10 @@ main (int argc, char **argv)
     }
 
     /* get property */
-    XGetWindowProperty (dpy, target_win, XInternAtom (dpy, OPACITY, False),
-                        0L, 1L, False, XA_CARDINAL, &actual, &format, &n, &left,
-                        (unsigned char **) &data);
-
-    if (data != None) {
+    if ((XGetWindowProperty (dpy, target_win, XInternAtom (dpy, OPACITY, False),
+                             0L, 1L, False, XA_CARDINAL, &actual, &format, &n,
+                             &left, &data) == Success)
+        && (data != None)) {
         memcpy (&current_opacity, data, sizeof (unsigned int));
         XFree ((void *) data);
         if (flag_verbose)
-- 
1.7.9.2



More information about the xorg-devel mailing list