[PATCH v2 22/25] [libx11] Checked return value of XGetWindowProperty and return false if it fails.

Alan Coopersmith alan.coopersmith at oracle.com
Tue Feb 1 00:25:07 PST 2011


On 01/31/11 04:02 AM, Erkki Seppälä wrote:
> Return value of "XGetWindowProperty(im->core.display, spec->lib_connect_wid, prop, 0L, (length + bytes_after_ret + 3UL) / 4UL, 1, 0UL, &type_ret, &format_ret, &nitems, &bytes_after_ret, &prop_ret)" is not checked
> 
> Signed-off-by: Erkki Seppälä <erkki.seppala at vincit.fi>
> ---
>  modules/im/ximcp/imTrX.c |   33 +++++++++++++++++++++------------
>  1 files changed, 21 insertions(+), 12 deletions(-)
> 
> diff --git a/modules/im/ximcp/imTrX.c b/modules/im/ximcp/imTrX.c
> index 47c231e..edcaf08 100644
> --- a/modules/im/ximcp/imTrX.c
> +++ b/modules/im/ximcp/imTrX.c
> @@ -377,14 +377,19 @@ _XimXGetReadData(
>  	    *ret_len  = (int)nitems;
>  	    if (bytes_after_ret > 0) {
>  		XFree(prop_ret);
> -	        XGetWindowProperty(im->core.display,
> -		    spec->lib_connect_wid, prop, 0L,
> -		    ((length + bytes_after_ret + 3)/ 4), True, AnyPropertyType,
> -		    &type_ret, &format_ret, &nitems, &bytes_after_ret,
> -		    &prop_ret);
> -	        XChangeProperty(im->core.display, spec->lib_connect_wid, prop,
> -		    XA_STRING, 8, PropModePrepend, &prop_ret[length],
> -		    (nitems - length));
> +		if (XGetWindowProperty(im->core.display,
> +				       spec->lib_connect_wid, prop, 0L,
> +				       ((length + bytes_after_ret + 3)/ 4),
> +				       True, AnyPropertyType,
> +				       &type_ret, &format_ret, &nitems,
> +				       &bytes_after_ret,
> +				       &prop_ret) == Success) {
> +		    XChangeProperty(im->core.display, spec->lib_connect_wid, prop,
> +				    XA_STRING, 8, PropModePrepend, &prop_ret[length],
> +				    (nitems - length));
> +		} else {
> +		    return False;
> +		}
>  	    }
>  	} else {
>  	    (void)memcpy(buf, prop_ret, buf_len);
> @@ -393,10 +398,14 @@ _XimXGetReadData(
>  
>  	    if (bytes_after_ret > 0) {
>  		XFree(prop_ret);
> -	        XGetWindowProperty(im->core.display,
> -		spec->lib_connect_wid, prop, 0L,
> -		((length + bytes_after_ret + 3)/ 4), True, AnyPropertyType,
> -		&type_ret, &format_ret, &nitems, &bytes_after_ret, &prop_ret);
> +		if (XGetWindowProperty(im->core.display,
> +				       spec->lib_connect_wid, prop, 0L,
> +				       ((length + bytes_after_ret + 3)/ 4),
> +				       True, AnyPropertyType,
> +				       &type_ret, &format_ret, &nitems,
> +				       &bytes_after_ret, &prop_ret) != Success) {
> +		    return False;
> +		}
>  	    }
>  	    XChangeProperty(im->core.display, spec->lib_connect_wid, prop,
>  		    XA_STRING, 8, PropModePrepend, &prop_ret[buf_len], len);

Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>

-- 
	-Alan Coopersmith-        alan.coopersmith at oracle.com
	 Oracle Solaris Platform Engineering: X Window System



More information about the xorg-devel mailing list