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:
Matthias Clasen 2005-05-18 14:46:14 +00:00 committed by Matthias Clasen
parent e7fc60f78f
commit f6906b8272
6 changed files with 55 additions and 14 deletions

View File

@ -1,5 +1,8 @@
2005-05-18 Matthias Clasen <mclasen@redhat.com>
* gdk/x11/gdkproperty-x11.c (gdk_property_get): Warn if
length overflows. (#161520, Ian Wienand)
* gtk/gtktoolbutton.c (gtk_tool_button_set_icon_name): Fix
parameter names to make gtk-doc happy.

View File

@ -1,5 +1,8 @@
2005-05-18 Matthias Clasen <mclasen@redhat.com>
* gdk/x11/gdkproperty-x11.c (gdk_property_get): Warn if
length overflows. (#161520, Ian Wienand)
* gtk/gtktoolbutton.c (gtk_tool_button_set_icon_name): Fix
parameter names to make gtk-doc happy.

View File

@ -1,5 +1,8 @@
2005-05-18 Matthias Clasen <mclasen@redhat.com>
* gdk/x11/gdkproperty-x11.c (gdk_property_get): Warn if
length overflows. (#161520, Ian Wienand)
* gtk/gtktoolbutton.c (gtk_tool_button_set_icon_name): Fix
parameter names to make gtk-doc happy.

View File

@ -1,5 +1,7 @@
2005-05-18 Matthias Clasen <mclasen@redhat.com>
* gdk/tmpl/properties.sgml: Updates.
* gtk/migrating-checklist.sgml: Add a section about named
icons.

View File

@ -42,6 +42,9 @@ data commonly stored in X window properties.
</para>
<!-- ##### SECTION Stability_Level ##### -->
<!-- ##### STRUCT GdkAtom ##### -->
<para>
An opaque type representing a string as an index into a table
@ -252,15 +255,14 @@ and %GDK_NONE will be stored in @actual_property_type.
</para>
<note>
<para>
The <function>XGetWindowProperty()</function>
function that gdk_property_get()
The XGetWindowProperty() function that gdk_property_get()
uses has a very confusing and complicated set of semantics.
Unfortunately, gdk_property_get() makes the situation
worse instead of better (the semantics should be considered
undefined), and also prints warnings to stderr in cases where it
should return a useful error to the program. You are advised to use
<function>XGetWindowProperty()</function>
directly until a replacement function for gdk_property_get()
XGetWindowProperty() directly until a replacement function for
gdk_property_get()
is provided.
</para>
</note>
@ -273,18 +275,24 @@ is provided.
be filled in, a warning will be printed to stderr
and no data will be returned.
@offset: the offset into the property at which to begin
retrieving data. (in 4 byte units!)
@length: the length of the data to delete. (in bytes, but
the actual retrieved length will be the next
integer multiple multiple of four greater than
this!)
retrieving data, in 4 byte units.
@length: the length of the data to retrieve in bytes. Data is
considered to be retrieved in 4 byte chunks, so @length
will be rounded up to the next highest 4 byte boundary
(so be careful not to pass a value that might overflow
when rounded up).
@pdelete: if %TRUE, delete the property after retrieving the
data.
@actual_property_type: location to store the actual type of
the property.
@actual_format: location to store the actual format of the data.
@actual_length: location to store the length of the retrieved
data, in bytes.
@actual_format: location to store the actual return format of the
data; either 8, 16 or 32 bits.
@actual_length: location to store the length of the retrieved data, in
bytes. Data returned in the 32 bit format is stored
in a long variable, so the actual number of 32 bit
elements should be be calculated via
@actual_length/sizeof(glong) to ensure portability to
64 bit systems.
@data: location to store a pointer to the data. The retrieved
data should be freed with g_free() when you are finished
using it.

View File

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