Skip to content

Commit

Permalink
Do not assume that text is null-terminated as pointed out by Christopher
Browse files Browse the repository at this point in the history
2007-08-07  Johan Dahlin  <jdahlin@async.com.br>

    * gtk/gtkbuilderparser.c (text): 
    * gtk/gtkcelllayout.c (attributes_text_element): 
    * gtk/gtkliststore.c (list_store_text): 
    Do not assume that text is null-terminated as pointed out by
    Christopher Fergeau


svn path=/trunk/; revision=18592
  • Loading branch information
Johan Dahlin authored and Johan Dahlin committed Aug 7, 2007
1 parent 923a1cf commit 12e1855
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
@@ -1,5 +1,11 @@
2007-08-07 Johan Dahlin <jdahlin@async.com.br>

* gtk/gtkbuilderparser.c (text):
* gtk/gtkcelllayout.c (attributes_text_element):
* gtk/gtkliststore.c (list_store_text):
Do not assume that text is null-terminated as pointed out by
Christopher Fergeau

* gtk/gtkbuilderparser.c (text): Use g_strdup on the translated
string instead of g_strndup() + the length of the untranslated
string. (#461945, Claude Paroz)
Expand Down
14 changes: 10 additions & 4 deletions gtk/gtkbuilderparser.c
Expand Up @@ -908,14 +908,20 @@ text (GMarkupParseContext *context,
{
PropertyInfo *prop_info = (PropertyInfo*)info;

/* text is not guaranteed to be null-terminated */
char *string = g_strndup (text, text_len);

if (prop_info->translatable && text_len)
{
if (prop_info->context)
text = dpgettext (data->domain, prop_info->context, text);
if (prop_info->context)
text = dpgettext (data->domain, prop_info->context, string);
else
text = dgettext (data->domain, text);
text = dgettext (data->domain, string);

g_free (string);
string = g_strdup (text);
}
prop_info->data = g_strdup (text);
prop_info->data = string;
}
}

Expand Down
12 changes: 8 additions & 4 deletions gtk/gtkcelllayout.c
Expand Up @@ -349,21 +349,25 @@ attributes_text_element (GMarkupParseContext *context,
AttributesSubParserData *parser_data = (AttributesSubParserData*)user_data;
glong l;
gchar *endptr;

gchar *string;

if (!parser_data->attr_name)
return;

errno = 0;
l = strtol (text, &endptr, 0);
if (errno || endptr == text)
string = g_strndup (text, text_len);
l = strtol (string, &endptr, 0);
if (errno || endptr == string)
{
g_set_error (error,
GTK_BUILDER_ERROR,
GTK_BUILDER_ERROR_INVALID_VALUE,
"Could not parse integer `%s'",
text);
string);
g_free (string);
return;
}
g_free (string);

gtk_cell_layout_add_attribute (parser_data->cell_layout,
parser_data->renderer,
Expand Down
5 changes: 4 additions & 1 deletion gtk/gtkliststore.c
Expand Up @@ -2188,15 +2188,17 @@ list_store_text (GMarkupParseContext *context,
SubParserData *data = (SubParserData*)user_data;
gint i;
GError *tmp_error = NULL;
gchar *string;

if (!data->is_data)
return;

i = data->row_column - 1;

string = g_strndup (text, text_len);
if (!gtk_builder_value_from_string_type (data->builder,
data->column_types[i],
text,
string,
&data->values[i],
&tmp_error))
{
Expand All @@ -2208,6 +2210,7 @@ list_store_text (GMarkupParseContext *context,
tmp_error->message);
g_error_free (tmp_error);
}
g_free (string);
}

static const GMarkupParser list_store_parser =
Expand Down

0 comments on commit 12e1855

Please sign in to comment.