Commit 2bea01ca authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

libgimp/gimpbrushmenu.c libgimp/gimpfontmenu.c libgimp/gimpgradientmenu.c

2005-03-23  Sven Neumann  <sven@gimp.org>

	* libgimp/gimpbrushmenu.c
	* libgimp/gimpfontmenu.c
	* libgimp/gimpgradientmenu.c
	* libgimp/gimppalettemenu.c
	* libgimp/gimppatternmenu.c: accept names passed over DND no matter
	whether they are NULL-terminated or not.

	* app/widgets/gimpselectiondata.c: same change here, also
	UTF8-validate the selection data before accepting it.
parent d3b0374e
2005-03-23 Sven Neumann <sven@gimp.org>
* libgimp/gimpbrushmenu.c
* libgimp/gimpfontmenu.c
* libgimp/gimpgradientmenu.c
* libgimp/gimppalettemenu.c
* libgimp/gimppatternmenu.c: accept names passed over DND no matter
whether they are NULL-terminated or not.
* app/widgets/gimpselectiondata.c: same change here, also
UTF8-validate the selection data before accepting it.
2005-03-23 Sven Neumann <sven@gimp.org> 2005-03-23 Sven Neumann <sven@gimp.org>
* libgimp/gimpbrushmenu.c * libgimp/gimpbrushmenu.c
......
...@@ -178,10 +178,10 @@ gimp_unescape_uri_string (const char *escaped, ...@@ -178,10 +178,10 @@ gimp_unescape_uri_string (const char *escaped,
GList * GList *
gimp_selection_data_get_uri_list (GtkSelectionData *selection) gimp_selection_data_get_uri_list (GtkSelectionData *selection)
{ {
GList *crap_list = NULL; GList *crap_list = NULL;
GList *uri_list = NULL; GList *uri_list = NULL;
GList *list; GList *list;
gchar *buffer; const gchar *buffer;
g_return_val_if_fail (selection != NULL, NULL); g_return_val_if_fail (selection != NULL, NULL);
...@@ -191,7 +191,7 @@ gimp_selection_data_get_uri_list (GtkSelectionData *selection) ...@@ -191,7 +191,7 @@ gimp_selection_data_get_uri_list (GtkSelectionData *selection)
return NULL; return NULL;
} }
buffer = (gchar *) selection->data; buffer = (const gchar *) selection->data;
D (g_print ("%s: raw buffer >>%s<<\n", G_STRFUNC, buffer)); D (g_print ("%s: raw buffer >>%s<<\n", G_STRFUNC, buffer));
...@@ -658,6 +658,19 @@ gimp_selection_data_set_viewable (GtkSelectionData *selection, ...@@ -658,6 +658,19 @@ gimp_selection_data_set_viewable (GtkSelectionData *selection,
8, (const guchar *) name, strlen (name) + 1); 8, (const guchar *) name, strlen (name) + 1);
} }
static gchar *
gimp_selection_data_get_name (GtkSelectionData *selection)
{
gchar *name = g_strndup (selection->data, selection->length);
if (g_utf8_validate (name, -1, NULL))
return name;
g_free (name);
return NULL;
}
GimpBrush * GimpBrush *
gimp_selection_data_get_brush (GtkSelectionData *selection, gimp_selection_data_get_brush (GtkSelectionData *selection,
Gimp *gimp) Gimp *gimp)
...@@ -674,7 +687,9 @@ gimp_selection_data_get_brush (GtkSelectionData *selection, ...@@ -674,7 +687,9 @@ gimp_selection_data_get_brush (GtkSelectionData *selection,
return NULL; return NULL;
} }
name = (gchar *) selection->data; name = gimp_selection_data_get_name (selection);
if (! name)
return NULL;
if (strcmp (name, "Standard") == 0) if (strcmp (name, "Standard") == 0)
brush = GIMP_BRUSH (gimp_brush_get_standard ()); brush = GIMP_BRUSH (gimp_brush_get_standard ());
...@@ -682,6 +697,8 @@ gimp_selection_data_get_brush (GtkSelectionData *selection, ...@@ -682,6 +697,8 @@ gimp_selection_data_get_brush (GtkSelectionData *selection,
brush = (GimpBrush *) brush = (GimpBrush *)
gimp_container_get_child_by_name (gimp->brush_factory->container, name); gimp_container_get_child_by_name (gimp->brush_factory->container, name);
g_free (name);
return brush; return brush;
} }
...@@ -701,7 +718,9 @@ gimp_selection_data_get_pattern (GtkSelectionData *selection, ...@@ -701,7 +718,9 @@ gimp_selection_data_get_pattern (GtkSelectionData *selection,
return NULL; return NULL;
} }
name = (gchar *) selection->data; name = gimp_selection_data_get_name (selection);
if (! name)
return NULL;
if (strcmp (name, "Standard") == 0) if (strcmp (name, "Standard") == 0)
pattern = GIMP_PATTERN (gimp_pattern_get_standard ()); pattern = GIMP_PATTERN (gimp_pattern_get_standard ());
...@@ -709,6 +728,8 @@ gimp_selection_data_get_pattern (GtkSelectionData *selection, ...@@ -709,6 +728,8 @@ gimp_selection_data_get_pattern (GtkSelectionData *selection,
pattern = (GimpPattern *) pattern = (GimpPattern *)
gimp_container_get_child_by_name (gimp->pattern_factory->container, name); gimp_container_get_child_by_name (gimp->pattern_factory->container, name);
g_free (name);
return pattern; return pattern;
} }
...@@ -728,7 +749,9 @@ gimp_selection_data_get_gradient (GtkSelectionData *selection, ...@@ -728,7 +749,9 @@ gimp_selection_data_get_gradient (GtkSelectionData *selection,
return NULL; return NULL;
} }
name = (gchar *) selection->data; name = gimp_selection_data_get_name (selection);
if (! name)
return NULL;
if (strcmp (name, "Standard") == 0) if (strcmp (name, "Standard") == 0)
gradient = GIMP_GRADIENT (gimp_gradient_get_standard ()); gradient = GIMP_GRADIENT (gimp_gradient_get_standard ());
...@@ -736,6 +759,8 @@ gimp_selection_data_get_gradient (GtkSelectionData *selection, ...@@ -736,6 +759,8 @@ gimp_selection_data_get_gradient (GtkSelectionData *selection,
gradient = (GimpGradient *) gradient = (GimpGradient *)
gimp_container_get_child_by_name (gimp->gradient_factory->container, name); gimp_container_get_child_by_name (gimp->gradient_factory->container, name);
g_free (name);
return gradient; return gradient;
} }
...@@ -755,7 +780,9 @@ gimp_selection_data_get_palette (GtkSelectionData *selection, ...@@ -755,7 +780,9 @@ gimp_selection_data_get_palette (GtkSelectionData *selection,
return NULL; return NULL;
} }
name = (gchar *) selection->data; name = gimp_selection_data_get_name (selection);
if (! name)
return NULL;
if (strcmp (name, "Standard") == 0) if (strcmp (name, "Standard") == 0)
palette = GIMP_PALETTE (gimp_palette_get_standard ()); palette = GIMP_PALETTE (gimp_palette_get_standard ());
...@@ -763,6 +790,8 @@ gimp_selection_data_get_palette (GtkSelectionData *selection, ...@@ -763,6 +790,8 @@ gimp_selection_data_get_palette (GtkSelectionData *selection,
palette = (GimpPalette *) palette = (GimpPalette *)
gimp_container_get_child_by_name (gimp->palette_factory->container, name); gimp_container_get_child_by_name (gimp->palette_factory->container, name);
g_free (name);
return palette; return palette;
} }
...@@ -782,7 +811,9 @@ gimp_selection_data_get_font (GtkSelectionData *selection, ...@@ -782,7 +811,9 @@ gimp_selection_data_get_font (GtkSelectionData *selection,
return NULL; return NULL;
} }
name = (gchar *) selection->data; name = gimp_selection_data_get_name (selection);
if (! name)
return NULL;
if (strcmp (name, "Standard") == 0) if (strcmp (name, "Standard") == 0)
font = gimp_font_get_standard (); font = gimp_font_get_standard ();
...@@ -790,6 +821,8 @@ gimp_selection_data_get_font (GtkSelectionData *selection, ...@@ -790,6 +821,8 @@ gimp_selection_data_get_font (GtkSelectionData *selection,
font = (GimpFont *) font = (GimpFont *)
gimp_container_get_child_by_name (gimp->fonts, name); gimp_container_get_child_by_name (gimp->fonts, name);
g_free (name);
return font; return font;
} }
...@@ -809,11 +842,15 @@ gimp_selection_data_get_buffer (GtkSelectionData *selection, ...@@ -809,11 +842,15 @@ gimp_selection_data_get_buffer (GtkSelectionData *selection,
return NULL; return NULL;
} }
name = (gchar *) selection->data; name = gimp_selection_data_get_name (selection);
if (! name)
return NULL;
buffer = (GimpBuffer *) buffer = (GimpBuffer *)
gimp_container_get_child_by_name (gimp->named_buffers, name); gimp_container_get_child_by_name (gimp->named_buffers, name);
g_free (name);
return buffer; return buffer;
} }
...@@ -833,11 +870,15 @@ gimp_selection_data_get_imagefile (GtkSelectionData *selection, ...@@ -833,11 +870,15 @@ gimp_selection_data_get_imagefile (GtkSelectionData *selection,
return NULL; return NULL;
} }
name = (gchar *) selection->data; name = gimp_selection_data_get_name (selection);
if (! name)
return NULL;
imagefile = (GimpImagefile *) imagefile = (GimpImagefile *)
gimp_container_get_child_by_name (gimp->documents, name); gimp_container_get_child_by_name (gimp->documents, name);
g_free (name);
return imagefile; return imagefile;
} }
...@@ -857,11 +898,15 @@ gimp_selection_data_get_template (GtkSelectionData *selection, ...@@ -857,11 +898,15 @@ gimp_selection_data_get_template (GtkSelectionData *selection,
return NULL; return NULL;
} }
name = (gchar *) selection->data; name = gimp_selection_data_get_name (selection);
if (! name)
return NULL;
template = (GimpTemplate *) template = (GimpTemplate *)
gimp_container_get_child_by_name (gimp->templates, name); gimp_container_get_child_by_name (gimp->templates, name);
g_free (name);
return template; return template;
} }
...@@ -881,7 +926,9 @@ gimp_selection_data_get_tool (GtkSelectionData *selection, ...@@ -881,7 +926,9 @@ gimp_selection_data_get_tool (GtkSelectionData *selection,
return NULL; return NULL;
} }
name = (gchar *) selection->data; name = gimp_selection_data_get_name (selection);
if (! name)
return NULL;
if (strcmp (name, "gimp-standard-tool") == 0) if (strcmp (name, "gimp-standard-tool") == 0)
tool_info = gimp_tool_info_get_standard (gimp); tool_info = gimp_tool_info_get_standard (gimp);
...@@ -889,5 +936,7 @@ gimp_selection_data_get_tool (GtkSelectionData *selection, ...@@ -889,5 +936,7 @@ gimp_selection_data_get_tool (GtkSelectionData *selection,
tool_info = (GimpToolInfo *) tool_info = (GimpToolInfo *)
gimp_container_get_child_by_name (gimp->tool_info_list, name); gimp_container_get_child_by_name (gimp->tool_info_list, name);
g_free (name);
return tool_info; return tool_info;
} }
...@@ -604,18 +604,18 @@ gimp_brush_select_drag_data_received (GtkWidget *preview, ...@@ -604,18 +604,18 @@ gimp_brush_select_drag_data_received (GtkWidget *preview,
guint time, guint time,
GtkWidget *widget) GtkWidget *widget)
{ {
gchar *name;
if ((selection->format != 8) || (selection->length < 1)) if ((selection->format != 8) || (selection->length < 1))
{ {
g_warning ("Received invalid brush data!"); g_warning ("Received invalid brush data!");
return; return;
} }
if (g_utf8_validate (selection->data, selection->length - 1, NULL)) name = g_strndup (selection->data, selection->length);
{
gchar *name = g_strndup (selection->data, selection->length - 1);
gimp_brush_select_widget_set (widget, name, -1.0, -1, -1); if (g_utf8_validate (name, -1, NULL))
gimp_brush_select_widget_set (widget, name, -1.0, -1, -1);
g_free (name); g_free (name);
}
} }
...@@ -257,18 +257,18 @@ gimp_font_select_drag_data_received (GtkWidget *widget, ...@@ -257,18 +257,18 @@ gimp_font_select_drag_data_received (GtkWidget *widget,
guint info, guint info,
guint time) guint time)
{ {
gchar *name;
if ((selection->format != 8) || (selection->length < 1)) if ((selection->format != 8) || (selection->length < 1))
{ {
g_warning ("Received invalid font data!"); g_warning ("Received invalid font data!");
return; return;
} }
if (g_utf8_validate (selection->data, selection->length - 1, NULL)) name = g_strndup (selection->data, selection->length);
{
gchar *name = g_strndup (selection->data, selection->length - 1);
gimp_font_select_widget_set (widget, name); if (g_utf8_validate (name, -1, NULL))
gimp_font_select_widget_set (widget, name);
g_free (name); g_free (name);
}
} }
...@@ -257,18 +257,18 @@ gimp_font_select_drag_data_received (GtkWidget *widget, ...@@ -257,18 +257,18 @@ gimp_font_select_drag_data_received (GtkWidget *widget,
guint info, guint info,
guint time) guint time)
{ {
gchar *name;
if ((selection->format != 8) || (selection->length < 1)) if ((selection->format != 8) || (selection->length < 1))
{ {
g_warning ("Received invalid font data!"); g_warning ("Received invalid font data!");
return; return;
} }
if (g_utf8_validate (selection->data, selection->length - 1, NULL)) name = g_strndup (selection->data, selection->length);
{
gchar *name = g_strndup (selection->data, selection->length - 1);
gimp_font_select_widget_set (widget, name); if (g_utf8_validate (name, -1, NULL))
gimp_font_select_widget_set (widget, name);
g_free (name); g_free (name);
}
} }
...@@ -414,18 +414,18 @@ gimp_gradient_select_drag_data_received (GtkWidget *widget, ...@@ -414,18 +414,18 @@ gimp_gradient_select_drag_data_received (GtkWidget *widget,
guint info, guint info,
guint time) guint time)
{ {
gchar *name;
if ((selection->format != 8) || (selection->length < 1)) if ((selection->format != 8) || (selection->length < 1))
{ {
g_warning ("Received invalid gradient data!"); g_warning ("Received invalid gradient data!");
return; return;
} }
if (g_utf8_validate (selection->data, selection->length - 1, NULL)) name = g_strndup (selection->data, selection->length);
{
gchar *name = g_strndup (selection->data, selection->length - 1);
gimp_gradient_select_widget_set (widget, name); if (g_utf8_validate (name, -1, NULL))
gimp_gradient_select_widget_set (widget, name);
g_free (name); g_free (name);
}
} }
...@@ -264,18 +264,18 @@ gimp_palette_select_drag_data_received (GtkWidget *widget, ...@@ -264,18 +264,18 @@ gimp_palette_select_drag_data_received (GtkWidget *widget,
guint info, guint info,
guint time) guint time)
{ {
gchar *name;
if ((selection->format != 8) || (selection->length < 1)) if ((selection->format != 8) || (selection->length < 1))
{ {
g_warning ("Received invalid palette data!"); g_warning ("Received invalid palette data!");
return; return;
} }
if (g_utf8_validate (selection->data, selection->length - 1, NULL)) name = g_strndup (selection->data, selection->length);
{
gchar *name = g_strndup (selection->data, selection->length - 1);
gimp_palette_select_widget_set (widget, name); if (g_utf8_validate (name, -1, NULL))
gimp_palette_select_widget_set (widget, name);
g_free (name); g_free (name);
}
} }
...@@ -498,18 +498,18 @@ gimp_pattern_select_drag_data_received (GtkWidget *preview, ...@@ -498,18 +498,18 @@ gimp_pattern_select_drag_data_received (GtkWidget *preview,
guint time, guint time,
GtkWidget *widget) GtkWidget *widget)
{ {
gchar *name;
if ((selection->format != 8) || (selection->length < 1)) if ((selection->format != 8) || (selection->length < 1))
{ {
g_warning ("Received invalid pattern data!"); g_warning ("Received invalid pattern data!");
return; return;
} }
if (g_utf8_validate (selection->data, selection->length - 1, NULL)) name = g_strndup (selection->data, selection->length);
{
gchar *name = g_strndup (selection->data, selection->length - 1);
gimp_pattern_select_widget_set (widget, name); if (g_utf8_validate (name, -1, NULL))
gimp_pattern_select_widget_set (widget, name);
g_free (name); g_free (name);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment