Warn if length overflows. (#161520, Ian Wienand)
2005-05-18 Matthias Clasen <mclasen@redhat.com> * gdk/x11/gdkproperty-x11.c (gdk_property_get): Warn if length overflows. (#161520, Ian Wienand)
This commit is contained in:
committed by
Matthias Clasen
parent
e7fc60f78f
commit
f6906b8272
@ -493,6 +493,7 @@ gdk_property_get (GdkWindow *window,
|
||||
gint ret_format;
|
||||
gulong ret_nitems;
|
||||
gulong ret_bytes_after;
|
||||
gulong get_length;
|
||||
gulong ret_length;
|
||||
guchar *ret_data;
|
||||
Atom xproperty;
|
||||
@ -521,9 +522,30 @@ gdk_property_get (GdkWindow *window,
|
||||
|
||||
ret_data = NULL;
|
||||
|
||||
/*
|
||||
* Round up length to next 4 byte value. Some code is in the (bad?)
|
||||
* habit of passing G_MAXLONG as the length argument, causing an
|
||||
* overflow to negative on the add. In this case, we clamp the
|
||||
* value to G_MAXLONG.
|
||||
*/
|
||||
get_length = length + 3;
|
||||
if (get_length > G_MAXLONG)
|
||||
{
|
||||
g_warning ("gdk_property_get(): length value has wrapped in calculation "
|
||||
"(did you pass G_MAXLONG?)");
|
||||
get_length = G_MAXLONG;
|
||||
}
|
||||
/* To fail, either the user passed 0 or G_MAXULONG */
|
||||
get_length = get_length / 4;
|
||||
if (get_length == 0)
|
||||
{
|
||||
g_warning ("gdk_propery-get(): invalid length 0");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
res = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
|
||||
GDK_WINDOW_XWINDOW (window), xproperty,
|
||||
offset, (length + 3) / 4, pdelete,
|
||||
offset, get_length, pdelete,
|
||||
xtype, &ret_prop_type, &ret_format,
|
||||
&ret_nitems, &ret_bytes_after,
|
||||
&ret_data);
|
||||
|
||||
Reference in New Issue
Block a user