From 07fae919a4474abfb55f41ed3d07bf93e74e9154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= Date: Thu, 3 Feb 2011 17:08:57 +0200 Subject: cmsProp: don't deal with uninitialized values, fail instead MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Properly handle the return value of XGetWindowProperty by considering if after the loop as well. Using freed pointer "prop_ret" There were numerous things wrong in how this function interacted with XGetWindowProperty. None of the local variables were initialized and remained that way if the call to XGetWindowProperty returned 1 (not Succeed). That doesn't result in after_ret being initialized in which case if it happens to be 0, the loop was exited. In that case format_ret and nitems_ret were uninitialized and the function might return with success (but with uninitialized pointer in prop_ret) or XcmsFailure. As the buffer enlarging code was called only when XGetWindowProperty failed (returned not Success), after_ret would not have been initialized. It would have been initialized only if the XGetWindowProperty has returned Success earlier, but in that case the code fragment would not have been reached. This patch alters the function to return XcmsFailure if the call to XGetWindowProperty fails. Reviewed-by: Alan Coopersmith Reviewed-by: Ander Conselvan de Oliveira Reviewed-by: Rami Ylimäki Signed-off-by: Erkki Seppälä Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/cmsProp.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'nx-X11/lib/X11/cmsProp.c') diff --git a/nx-X11/lib/X11/cmsProp.c b/nx-X11/lib/X11/cmsProp.c index 0e8f8a2ba..7e1a70310 100644 --- a/nx-X11/lib/X11/cmsProp.c +++ b/nx-X11/lib/X11/cmsProp.c @@ -125,20 +125,23 @@ _XcmsGetProperty( unsigned long nitems_ret, after_ret; #endif Atom atom_ret; + int xgwp_ret; - while (XGetWindowProperty (pDpy, w, property, 0, len, False, - XA_INTEGER, &atom_ret, &format_ret, - &nitems_ret, &after_ret, - (unsigned char **)&prop_ret)) { - if (after_ret > 0) { + while (True) { + xgwp_ret = XGetWindowProperty (pDpy, w, property, 0, len, False, + XA_INTEGER, &atom_ret, &format_ret, + &nitems_ret, &after_ret, + (unsigned char **)&prop_ret); + if (xgwp_ret == Success && after_ret > 0) { len += nitems_ret * (format_ret >> 3); XFree (prop_ret); } else { break; } } - if (format_ret == 0 || nitems_ret == 0) { - /* the property does not exist or is of an unexpected type */ + if (xgwp_ret != Success || format_ret == 0 || nitems_ret == 0) { + /* the property does not exist or is of an unexpected type or + getting window property failed */ return(XcmsFailure); } -- cgit v1.2.3 From e2e45b2b3abf46e4e5c27d7c655769f2b693446e Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Fri, 7 Oct 2016 23:46:05 +0200 Subject: Align files with upstream libX11-1.6.0 This commit looks a bit crazy at first glance. It (re-)introduces lots of whitespaces and bad formatting. Explanation: Backporting upstream changes lead to commits being applied out of order. This meant a lot of manual intervention which in turn lead to slight differences between upstream and NX. With this commit these slight differences are minimized which will be of great help when adding further upstream patches. --- nx-X11/lib/X11/cmsProp.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'nx-X11/lib/X11/cmsProp.c') diff --git a/nx-X11/lib/X11/cmsProp.c b/nx-X11/lib/X11/cmsProp.c index 7e1a70310..a7aa5b5c5 100644 --- a/nx-X11/lib/X11/cmsProp.c +++ b/nx-X11/lib/X11/cmsProp.c @@ -128,11 +128,11 @@ _XcmsGetProperty( int xgwp_ret; while (True) { - xgwp_ret = XGetWindowProperty (pDpy, w, property, 0, len, False, - XA_INTEGER, &atom_ret, &format_ret, - &nitems_ret, &after_ret, - (unsigned char **)&prop_ret); - if (xgwp_ret == Success && after_ret > 0) { + xgwp_ret = XGetWindowProperty (pDpy, w, property, 0, len, False, + XA_INTEGER, &atom_ret, &format_ret, + &nitems_ret, &after_ret, + (unsigned char **)&prop_ret); + if (xgwp_ret == Success && after_ret > 0) { len += nitems_ret * (format_ret >> 3); XFree (prop_ret); } else { @@ -140,7 +140,7 @@ _XcmsGetProperty( } } if (xgwp_ret != Success || format_ret == 0 || nitems_ret == 0) { - /* the property does not exist or is of an unexpected type or + /* the property does not exist or is of an unexpected type or getting window property failed */ return(XcmsFailure); } -- cgit v1.2.3