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

Hans de Goede hdegoede at redhat.com
Mon Jan 5 07:00:22 PST 2015


Hi,

On 03-01-15 23:29, Alan Coopersmith wrote:
> 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>

Looks good:

Reviewed-by: Hans de Goede <hdegoede at redhat.com>

Regards,

Hans

> ---
>   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)
>


More information about the xorg-devel mailing list