Commit 083c7c91 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

app/plug_in.c app/core/gimpbrush.c app/core/gimpbrushpipe.c

2001-09-03  Sven Neumann  <sven@gimp.org>

	* app/plug_in.c
	* app/core/gimpbrush.c
	* app/core/gimpbrushpipe.c
	* app/core/gimpgradient.c
	* app/core/gimppalette.c
	* app/core/gimppattern.c: check strings from data files and plug-in
	registration for UTF-8 validity. There are probably a lot more places
	that need these checks.

	* plug-ins/common/gqbist.c: converted PDB texts to UTF-8.
parent 4e9fcfa6
2001-09-03 Sven Neumann <sven@gimp.org>
* app/plug_in.c
* app/core/gimpbrush.c
* app/core/gimpbrushpipe.c
* app/core/gimpgradient.c
* app/core/gimppalette.c
* app/core/gimppattern.c: check strings from data files and plug-in
registration for UTF-8 validity. There are probably a lot more places
that need these checks.
* plug-ins/common/gqbist.c: converted PDB texts to UTF-8.
2001-08-31 Thomas Canty <tommydal@optushome.com.au>
* app/colormaps.c
* app/gdisplay.c
* app/nav_window.c
......
......@@ -1833,6 +1833,7 @@ plug_in_handle_proc_install (GPProcInstall *proc_install)
GSList *tmp = NULL;
gchar *prog = NULL;
gboolean add_proc_def;
gboolean valid;
gint i;
/* Argument checking
......@@ -1890,10 +1891,10 @@ plug_in_handle_proc_install (GPProcInstall *proc_install)
else if (strncmp (proc_install->menu_path, "<Save>", 6) == 0)
{
if ((proc_install->nparams < 5) ||
(proc_install->params[0].type != GIMP_PDB_INT32) ||
(proc_install->params[1].type != GIMP_PDB_IMAGE) ||
(proc_install->params[0].type != GIMP_PDB_INT32) ||
(proc_install->params[1].type != GIMP_PDB_IMAGE) ||
(proc_install->params[2].type != GIMP_PDB_DRAWABLE) ||
(proc_install->params[3].type != GIMP_PDB_STRING) ||
(proc_install->params[3].type != GIMP_PDB_STRING) ||
(proc_install->params[4].type != GIMP_PDB_STRING))
{
g_message ("Plug-In \"%s\"\n(%s)\n"
......@@ -1924,9 +1925,10 @@ plug_in_handle_proc_install (GPProcInstall *proc_install)
for (i = 1; i < proc_install->nparams; i++)
{
if ((proc_install->params[i].type == GIMP_PDB_INT32ARRAY ||
proc_install->params[i].type == GIMP_PDB_INT8ARRAY ||
proc_install->params[i].type == GIMP_PDB_INT8ARRAY ||
proc_install->params[i].type == GIMP_PDB_FLOATARRAY ||
proc_install->params[i].type == GIMP_PDB_STRINGARRAY) &&
proc_install->params[i].type == GIMP_PDB_STRINGARRAY)
&&
proc_install->params[i-1].type != GIMP_PDB_INT32)
{
g_message ("Plug-In \"%s\"\n(%s)\n"
......@@ -1939,7 +1941,50 @@ plug_in_handle_proc_install (GPProcInstall *proc_install)
return;
}
}
/* Sanity check strings for UTF-8 validity */
valid = FALSE;
if ((proc_install->menu_path == NULL ||
g_utf8_validate (proc_install->menu_path, -1, NULL)) &&
(g_utf8_validate (proc_install->name, -1, NULL)) &&
(proc_install->blurb == NULL ||
g_utf8_validate (proc_install->blurb, -1, NULL)) &&
(proc_install->help == NULL ||
g_utf8_validate (proc_install->help, -1, NULL)) &&
(proc_install->author == NULL ||
g_utf8_validate (proc_install->author, -1, NULL)) &&
(proc_install->copyright == NULL ||
g_utf8_validate (proc_install->copyright, -1, NULL)) &&
(proc_install->date == NULL ||
g_utf8_validate (proc_install->date, -1, NULL)))
{
valid = TRUE;
for (i = 0; i < proc_install->nparams && valid; i++)
{
if (! (g_utf8_validate (proc_install->params[i].name, -1, NULL) &&
(proc_install->params[i].description == NULL ||
g_utf8_validate (proc_install->params[i].description, -1, NULL))))
valid = FALSE;
}
for (i = 0; i < proc_install->nreturn_vals && valid; i++)
{
if (! (g_utf8_validate (proc_install->return_vals[i].name, -1, NULL) &&
(proc_install->return_vals[i].description == NULL ||
g_utf8_validate (proc_install->return_vals[i].description, -1, NULL))))
valid = FALSE;
}
}
if (!valid)
{
g_message ("Plug-In \"%s\"\n(%s)\n"
"attempted to install a procedure with invalid UTF-8 strings.\n",
g_path_get_basename (current_plug_in->args[0]),
current_plug_in->args[0]);
return;
}
/* Initialization */
......
......@@ -429,7 +429,7 @@ gimp_brush_load_brush (gint fd,
GimpBrush *brush;
gint bn_size;
BrushHeader header;
gchar *name;
gchar *name = NULL;
gint i;
g_return_val_if_fail (filename != NULL, NULL);
......@@ -477,11 +477,18 @@ gimp_brush_load_brush (gint fd,
g_free (name);
return NULL;
}
if (!g_utf8_validate (name, -1, NULL))
{
g_message (_("Invalid UTF-8 string in GIMP brush file \"%s\"."),
filename);
g_free (name);
name = NULL;
}
}
else
{
name = g_strdup (_("Unnamed"));
}
if (!name)
name = g_strdup (_("Unnamed"));
switch (header.bytes)
{
......
......@@ -429,7 +429,7 @@ gimp_brush_load_brush (gint fd,
GimpBrush *brush;
gint bn_size;
BrushHeader header;
gchar *name;
gchar *name = NULL;
gint i;
g_return_val_if_fail (filename != NULL, NULL);
......@@ -477,11 +477,18 @@ gimp_brush_load_brush (gint fd,
g_free (name);
return NULL;
}
if (!g_utf8_validate (name, -1, NULL))
{
g_message (_("Invalid UTF-8 string in GIMP brush file \"%s\"."),
filename);
g_free (name);
name = NULL;
}
}
else
{
name = g_strdup (_("Unnamed"));
}
if (!name)
name = g_strdup (_("Unnamed"));
switch (header.bytes)
{
......
......@@ -300,13 +300,23 @@ gimp_brush_pipe_load (const gchar *filename)
if (buffer->len > 0 && buffer->len < 1024)
{
pipe = GIMP_BRUSH_PIPE (g_object_new (GIMP_TYPE_BRUSH_PIPE, NULL));
gimp_object_set_name (GIMP_OBJECT (pipe), buffer->str);
if (g_utf8_validate (buffer->str, buffer->len, NULL))
{
gimp_object_set_name (GIMP_OBJECT (pipe), buffer->str);
}
else
{
g_message (_("Invalid UTF-8 string in GIMP brush file \"%s\"."),
filename);
gimp_object_set_name (GIMP_OBJECT (pipe), _("Unnamed"));
}
}
g_string_free (buffer, TRUE);
if (!pipe)
{
g_message ("Couldn't read name for brush pipe from file '%s'\n",
g_message ("Couldn't read name for brush pipe from file \"%s\".\n",
filename);
close (fd);
return NULL;
......
......@@ -300,13 +300,23 @@ gimp_brush_pipe_load (const gchar *filename)
if (buffer->len > 0 && buffer->len < 1024)
{
pipe = GIMP_BRUSH_PIPE (g_object_new (GIMP_TYPE_BRUSH_PIPE, NULL));
gimp_object_set_name (GIMP_OBJECT (pipe), buffer->str);
if (g_utf8_validate (buffer->str, buffer->len, NULL))
{
gimp_object_set_name (GIMP_OBJECT (pipe), buffer->str);
}
else
{
g_message (_("Invalid UTF-8 string in GIMP brush file \"%s\"."),
filename);
gimp_object_set_name (GIMP_OBJECT (pipe), _("Unnamed"));
}
}
g_string_free (buffer, TRUE);
if (!pipe)
{
g_message ("Couldn't read name for brush pipe from file '%s'\n",
g_message ("Couldn't read name for brush pipe from file \"%s\".\n",
filename);
close (fd);
return NULL;
......
......@@ -320,8 +320,17 @@ gimp_gradient_load (const gchar *filename)
fgets (line, 1024, file);
if (! strncmp (line, "Name: ", strlen ("Name: ")))
{
gimp_object_set_name (GIMP_OBJECT (gradient),
g_strstrip (&line[strlen ("Name: ")]));
if (g_utf8_validate (line, -1, NULL))
{
gimp_object_set_name (GIMP_OBJECT (gradient),
g_strstrip (&line[strlen ("Name: ")]));
}
else
{
g_message (_("Invalid UTF-8 string in GIMP gradient file \"%s\"."),
filename);
gimp_object_set_name (GIMP_OBJECT (gradient), _("Unnamed"));
}
fgets (line, 1024, file);
}
......
......@@ -301,8 +301,16 @@ gimp_palette_load (const gchar *filename)
if (! strncmp (str, "Name: ", strlen ("Name: ")))
{
gimp_object_set_name (GIMP_OBJECT (palette),
g_strstrip (&str[strlen ("Name: ")]));
if (g_utf8_validate (str, -1, NULL))
{
gimp_object_set_name (GIMP_OBJECT (palette),
g_strstrip (&str[strlen ("Name: ")]));
}
else
{
g_message (_("Invalid UTF-8 string in palette file '%s'"), filename);
gimp_object_set_name (GIMP_OBJECT (palette), _("Unnamed"));
}
if (! fgets (str, 1024, fp))
{
......@@ -487,7 +495,6 @@ gimp_palette_add_entry (GimpPalette *palette,
{
GimpPaletteEntry *entry;
g_return_val_if_fail (palette != NULL, NULL);
g_return_val_if_fail (GIMP_IS_PALETTE (palette), NULL);
g_return_val_if_fail (color != NULL, NULL);
......@@ -514,7 +521,6 @@ gimp_palette_delete_entry (GimpPalette *palette,
GList *list;
gint pos = 0;
g_return_if_fail (palette != NULL);
g_return_if_fail (GIMP_IS_PALETTE (palette));
g_return_if_fail (entry != NULL);
......
......@@ -301,8 +301,16 @@ gimp_palette_load (const gchar *filename)
if (! strncmp (str, "Name: ", strlen ("Name: ")))
{
gimp_object_set_name (GIMP_OBJECT (palette),
g_strstrip (&str[strlen ("Name: ")]));
if (g_utf8_validate (str, -1, NULL))
{
gimp_object_set_name (GIMP_OBJECT (palette),
g_strstrip (&str[strlen ("Name: ")]));
}
else
{
g_message (_("Invalid UTF-8 string in palette file '%s'"), filename);
gimp_object_set_name (GIMP_OBJECT (palette), _("Unnamed"));
}
if (! fgets (str, 1024, fp))
{
......@@ -487,7 +495,6 @@ gimp_palette_add_entry (GimpPalette *palette,
{
GimpPaletteEntry *entry;
g_return_val_if_fail (palette != NULL, NULL);
g_return_val_if_fail (GIMP_IS_PALETTE (palette), NULL);
g_return_val_if_fail (color != NULL, NULL);
......@@ -514,7 +521,6 @@ gimp_palette_delete_entry (GimpPalette *palette,
GList *list;
gint pos = 0;
g_return_if_fail (palette != NULL);
g_return_if_fail (GIMP_IS_PALETTE (palette));
g_return_if_fail (entry != NULL);
......
......@@ -301,8 +301,16 @@ gimp_palette_load (const gchar *filename)
if (! strncmp (str, "Name: ", strlen ("Name: ")))
{
gimp_object_set_name (GIMP_OBJECT (palette),
g_strstrip (&str[strlen ("Name: ")]));
if (g_utf8_validate (str, -1, NULL))
{
gimp_object_set_name (GIMP_OBJECT (palette),
g_strstrip (&str[strlen ("Name: ")]));
}
else
{
g_message (_("Invalid UTF-8 string in palette file '%s'"), filename);
gimp_object_set_name (GIMP_OBJECT (palette), _("Unnamed"));
}
if (! fgets (str, 1024, fp))
{
......@@ -487,7 +495,6 @@ gimp_palette_add_entry (GimpPalette *palette,
{
GimpPaletteEntry *entry;
g_return_val_if_fail (palette != NULL, NULL);
g_return_val_if_fail (GIMP_IS_PALETTE (palette), NULL);
g_return_val_if_fail (color != NULL, NULL);
......@@ -514,7 +521,6 @@ gimp_palette_delete_entry (GimpPalette *palette,
GList *list;
gint pos = 0;
g_return_if_fail (palette != NULL);
g_return_if_fail (GIMP_IS_PALETTE (palette));
g_return_if_fail (entry != NULL);
......
......@@ -312,11 +312,18 @@ gimp_pattern_load (const gchar *filename)
g_message (_("Error in GIMP pattern file \"%s\"."), filename);
goto error;
}
if (!g_utf8_validate (name, -1, NULL))
{
g_message (_("Invalid UTF-8 string in GIMP pattern file \"%s\"."),
filename);
g_free (name);
name = NULL;
}
}
else
{
name = g_strdup (_("Unnamed"));
}
if (!name)
name = g_strdup (_("Unnamed"));
pattern = GIMP_PATTERN (g_object_new (GIMP_TYPE_PATTERN, NULL));
......
......@@ -312,11 +312,18 @@ gimp_pattern_load (const gchar *filename)
g_message (_("Error in GIMP pattern file \"%s\"."), filename);
goto error;
}
if (!g_utf8_validate (name, -1, NULL))
{
g_message (_("Invalid UTF-8 string in GIMP pattern file \"%s\"."),
filename);
g_free (name);
name = NULL;
}
}
else
{
name = g_strdup (_("Unnamed"));
}
if (!name)
name = g_strdup (_("Unnamed"));
pattern = GIMP_PATTERN (g_object_new (GIMP_TYPE_PATTERN, NULL));
......
......@@ -1833,6 +1833,7 @@ plug_in_handle_proc_install (GPProcInstall *proc_install)
GSList *tmp = NULL;
gchar *prog = NULL;
gboolean add_proc_def;
gboolean valid;
gint i;
/* Argument checking
......@@ -1890,10 +1891,10 @@ plug_in_handle_proc_install (GPProcInstall *proc_install)
else if (strncmp (proc_install->menu_path, "<Save>", 6) == 0)
{
if ((proc_install->nparams < 5) ||
(proc_install->params[0].type != GIMP_PDB_INT32) ||
(proc_install->params[1].type != GIMP_PDB_IMAGE) ||
(proc_install->params[0].type != GIMP_PDB_INT32) ||
(proc_install->params[1].type != GIMP_PDB_IMAGE) ||
(proc_install->params[2].type != GIMP_PDB_DRAWABLE) ||
(proc_install->params[3].type != GIMP_PDB_STRING) ||
(proc_install->params[3].type != GIMP_PDB_STRING) ||
(proc_install->params[4].type != GIMP_PDB_STRING))
{
g_message ("Plug-In \"%s\"\n(%s)\n"
......@@ -1924,9 +1925,10 @@ plug_in_handle_proc_install (GPProcInstall *proc_install)
for (i = 1; i < proc_install->nparams; i++)
{
if ((proc_install->params[i].type == GIMP_PDB_INT32ARRAY ||
proc_install->params[i].type == GIMP_PDB_INT8ARRAY ||
proc_install->params[i].type == GIMP_PDB_INT8ARRAY ||
proc_install->params[i].type == GIMP_PDB_FLOATARRAY ||
proc_install->params[i].type == GIMP_PDB_STRINGARRAY) &&
proc_install->params[i].type == GIMP_PDB_STRINGARRAY)
&&
proc_install->params[i-1].type != GIMP_PDB_INT32)
{
g_message ("Plug-In \"%s\"\n(%s)\n"
......@@ -1939,7 +1941,50 @@ plug_in_handle_proc_install (GPProcInstall *proc_install)
return;
}
}
/* Sanity check strings for UTF-8 validity */
valid = FALSE;
if ((proc_install->menu_path == NULL ||
g_utf8_validate (proc_install->menu_path, -1, NULL)) &&
(g_utf8_validate (proc_install->name, -1, NULL)) &&
(proc_install->blurb == NULL ||
g_utf8_validate (proc_install->blurb, -1, NULL)) &&
(proc_install->help == NULL ||
g_utf8_validate (proc_install->help, -1, NULL)) &&
(proc_install->author == NULL ||
g_utf8_validate (proc_install->author, -1, NULL)) &&
(proc_install->copyright == NULL ||
g_utf8_validate (proc_install->copyright, -1, NULL)) &&
(proc_install->date == NULL ||
g_utf8_validate (proc_install->date, -1, NULL)))
{
valid = TRUE;
for (i = 0; i < proc_install->nparams && valid; i++)
{
if (! (g_utf8_validate (proc_install->params[i].name, -1, NULL) &&
(proc_install->params[i].description == NULL ||
g_utf8_validate (proc_install->params[i].description, -1, NULL))))
valid = FALSE;
}
for (i = 0; i < proc_install->nreturn_vals && valid; i++)
{
if (! (g_utf8_validate (proc_install->return_vals[i].name, -1, NULL) &&
(proc_install->return_vals[i].description == NULL ||
g_utf8_validate (proc_install->return_vals[i].description, -1, NULL))))
valid = FALSE;
}
}
if (!valid)
{
g_message ("Plug-In \"%s\"\n(%s)\n"
"attempted to install a procedure with invalid UTF-8 strings.\n",
g_path_get_basename (current_plug_in->args[0]),
current_plug_in->args[0]);
return;
}
/* Initialization */
......
......@@ -1833,6 +1833,7 @@ plug_in_handle_proc_install (GPProcInstall *proc_install)
GSList *tmp = NULL;
gchar *prog = NULL;
gboolean add_proc_def;
gboolean valid;
gint i;
/* Argument checking
......@@ -1890,10 +1891,10 @@ plug_in_handle_proc_install (GPProcInstall *proc_install)
else if (strncmp (proc_install->menu_path, "<Save>", 6) == 0)
{
if ((proc_install->nparams < 5) ||
(proc_install->params[0].type != GIMP_PDB_INT32) ||
(proc_install->params[1].type != GIMP_PDB_IMAGE) ||
(proc_install->params[0].type != GIMP_PDB_INT32) ||
(proc_install->params[1].type != GIMP_PDB_IMAGE) ||
(proc_install->params[2].type != GIMP_PDB_DRAWABLE) ||
(proc_install->params[3].type != GIMP_PDB_STRING) ||
(proc_install->params[3].type != GIMP_PDB_STRING) ||
(proc_install->params[4].type != GIMP_PDB_STRING))
{
g_message ("Plug-In \"%s\"\n(%s)\n"
......@@ -1924,9 +1925,10 @@ plug_in_handle_proc_install (GPProcInstall *proc_install)
for (i = 1; i < proc_install->nparams; i++)
{
if ((proc_install->params[i].type == GIMP_PDB_INT32ARRAY ||
proc_install->params[i].type == GIMP_PDB_INT8ARRAY ||
proc_install->params[i].type == GIMP_PDB_INT8ARRAY ||
proc_install->params[i].type == GIMP_PDB_FLOATARRAY ||
proc_install->params[i].type == GIMP_PDB_STRINGARRAY) &&
proc_install->params[i].type == GIMP_PDB_STRINGARRAY)
&&
proc_install->params[i-1].type != GIMP_PDB_INT32)
{
g_message ("Plug-In \"%s\"\n(%s)\n"
......@@ -1939,7 +1941,50 @@ plug_in_handle_proc_install (GPProcInstall *proc_install)
return;
}
}
/* Sanity check strings for UTF-8 validity */
valid = FALSE;
if ((proc_install->menu_path == NULL ||
g_utf8_validate (proc_install->menu_path, -1, NULL)) &&
(g_utf8_validate (proc_install->name, -1, NULL)) &&
(proc_install->blurb == NULL ||
g_utf8_validate (proc_install->blurb, -1, NULL)) &&
(proc_install->help == NULL ||
g_utf8_validate (proc_install->help, -1, NULL)) &&
(proc_install->author == NULL ||
g_utf8_validate (proc_install->author, -1, NULL)) &&
(proc_install->copyright == NULL ||
g_utf8_validate (proc_install->copyright, -1, NULL)) &&
(proc_install->date == NULL ||
g_utf8_validate (proc_install->date, -1, NULL)))
{
valid = TRUE;
for (i = 0; i < proc_install->nparams && valid; i++)
{
if (! (g_utf8_validate (proc_install->params[i].name, -1, NULL) &&
(proc_install->params[i].description == NULL ||
g_utf8_validate (proc_install->params[i].description, -1, NULL))))
valid = FALSE;
}
for (i = 0; i < proc_install->nreturn_vals && valid; i++)
{
if (! (g_utf8_validate (proc_install->return_vals[i].name, -1, NULL) &&
(proc_install->return_vals[i].description == NULL ||
g_utf8_validate (proc_install->return_vals[i].description, -1, NULL))))
valid = FALSE;
}
}
if (!valid)
{
g_message ("Plug-In \"%s\"\n(%s)\n"
"attempted to install a procedure with invalid UTF-8 strings.\n",
g_path_get_basename (current_plug_in->args[0]),
current_plug_in->args[0]);
return;
}
/* Initialization */
......
......@@ -1833,6 +1833,7 @@ plug_in_handle_proc_install (GPProcInstall *proc_install)
GSList *tmp = NULL;
gchar *prog = NULL;
gboolean add_proc_def;
gboolean valid;
gint i;
/* Argument checking
......@@ -1890,10 +1891,10 @@ plug_in_handle_proc_install (GPProcInstall *proc_install)
else if (strncmp (proc_install->menu_path, "<Save>", 6) == 0)
{
if ((proc_install->nparams < 5) ||
(proc_install->params[0].type != GIMP_PDB_INT32) ||
(proc_install->params[1].type != GIMP_PDB_IMAGE) ||
(proc_install->params[0].type != GIMP_PDB_INT32) ||
(proc_install->params[1].type != GIMP_PDB_IMAGE) ||
(proc_install->params[2].type != GIMP_PDB_DRAWABLE) ||
(proc_install->params[3].type != GIMP_PDB_STRING) ||
(proc_install->params[3].type != GIMP_PDB_STRING) ||
(proc_install->params[4].type != GIMP_PDB_STRING))
{
g_message ("Plug-In \"%s\"\n(%s)\n"
......@@ -1924,9 +1925,10 @@ plug_in_handle_proc_install (GPProcInstall *proc_install)
for (i = 1; i < proc_install->nparams; i++)
{
if ((proc_install->params[i].type == GIMP_PDB_INT32ARRAY ||
proc_install->params[i].type == GIMP_PDB_INT8ARRAY ||
proc_install->params[i].type == GIMP_PDB_INT8ARRAY ||
proc_install->params[i].type == GIMP_PDB_FLOATARRAY ||
proc_install->params[i].type == GIMP_PDB_STRINGARRAY) &&
proc_install->params[i].type == GIMP_PDB_STRINGARRAY)