app: better handling of failure of gimp_scanner_parse_string().

This fixes 2 issues:

1. gimp_scanner_parse_string() may fail, which here would indicate broken input.
   If it does, the string variable would not be set, so we need to initialize it
   to NULL, otherwise freeing it could crash GIMP.
2. The variables set by gimp_scanner_parse_string() must be freed.
This commit is contained in:
Jehan 2023-09-22 15:24:22 +02:00
parent ae38b433f8
commit 12d8401d65
2 changed files with 7 additions and 4 deletions

View File

@ -263,7 +263,7 @@ gimp_font_deserialize_create (GType type,
*/
if (g_scanner_peek_next_token (scanner) == G_TOKEN_STRING)
{
gchar* font_name;
gchar* font_name = NULL;
gimp_scanner_parse_string (scanner, &font_name);
@ -282,6 +282,8 @@ gimp_font_deserialize_create (GType type,
else
g_object_ref (font);
g_free (font_name);
return GIMP_CONFIG (GIMP_FONT (font));
}

View File

@ -923,7 +923,7 @@ gimp_text_deserialize_property (GimpConfig *object,
}
else if (property_id == PROP_MARKUP)
{
gchar *markup;
gchar *markup = NULL;
GString *markup_str;
GimpFont *dummy_object = g_object_new (GIMP_TYPE_FONT, NULL);
@ -936,7 +936,7 @@ gimp_text_deserialize_property (GimpConfig *object,
{
while (g_scanner_peek_next_token (scanner) == G_TOKEN_STRING)
{
gchar *markup_fontname;
gchar *markup_fontname = NULL;
gchar *replaced_markup;
gchar *new_markup;
GimpFont *font;
@ -969,7 +969,7 @@ gimp_text_deserialize_property (GimpConfig *object,
{
while (g_scanner_peek_next_token (scanner) == G_TOKEN_LEFT_PAREN)
{
gchar *lookupname;
gchar *lookupname = NULL;
gchar *replaced_markup;
gchar *new_markup;
GimpFont *font;
@ -1003,6 +1003,7 @@ gimp_text_deserialize_property (GimpConfig *object,
g_object_unref (dummy_object);
g_string_free (markup_str, TRUE);
g_free (markup);
return TRUE;
}