summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2018-04-05 18:18:55 +0200
committerBenjamin Otte <otte@redhat.com>2018-04-05 18:41:34 +0200
commit47ea3a9452becc5b707617557ec03ceaeac87ada (patch)
tree0da8bf85c74736e7a357ecc7a519868802c98e1e
parent1792f3b21efbd8fe04cf49f2b1b9f731e8c191ca (diff)
downloadgtk+-47ea3a9452becc5b707617557ec03ceaeac87ada.tar.gz
snapshot: Don't cause invalid reads
1. Pass clip rectangles to gtk_snapshot_push_state() that point into the state array. 2. g_array_set_size(len+1) the state array 3. Make that function realloc() the state array. 4. The clip rectangle now points into invalid memory 5. Use the clip array This patch fixes things by moving step 5 to before step 2.
-rw-r--r--gtk/gtksnapshot.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c
index c383364275..ad7b2d358a 100644
--- a/gtk/gtksnapshot.c
+++ b/gtk/gtksnapshot.c
@@ -116,24 +116,24 @@ gtk_snapshot_push_state (GtkSnapshot *snapshot,
int translate_y,
GtkSnapshotCollectFunc collect_func)
{
- GtkSnapshotState *state;
-
- g_array_set_size (snapshot->state_stack, snapshot->state_stack->len + 1);
- state = &g_array_index (snapshot->state_stack, GtkSnapshotState, snapshot->state_stack->len - 1);
+ GtkSnapshotState state = { 0, };
- state->name = name;
+ state.name = name;
if (clip)
{
- state->clip = *clip;
- state->has_clip = TRUE;
+ state.clip = *clip;
+ state.has_clip = TRUE;
}
- state->translate_x = translate_x;
- state->translate_y = translate_y;
- state->collect_func = collect_func;
- state->start_node_index = snapshot->nodes->len;
- state->n_nodes = 0;
- return state;
+ state.translate_x = translate_x;
+ state.translate_y = translate_y;
+ state.collect_func = collect_func;
+ state.start_node_index = snapshot->nodes->len;
+ state.n_nodes = 0;
+
+ g_array_append_val (snapshot->state_stack, state);
+
+ return &g_array_index (snapshot->state_stack, GtkSnapshotState, snapshot->state_stack->len - 1);
}
static GtkSnapshotState *