From 91d302a2015719bba5f6bca26212475f777d85a7 Mon Sep 17 00:00:00 2001 From: "G.Willems" Date: Sat, 24 Jun 2023 03:05:37 +0200 Subject: [PATCH] stack: fix pages list bounds check Fix integer underflow when children->len is 0. Add missing bounds check in select_item() --- gtk/gtkstack.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gtk/gtkstack.c b/gtk/gtkstack.c index dad2036250..b56d24d9c0 100644 --- a/gtk/gtkstack.c +++ b/gtk/gtkstack.c @@ -617,8 +617,7 @@ gtk_stack_pages_get_item (GListModel *model, GtkStackPrivate *priv = gtk_stack_get_instance_private (pages->stack); GtkStackPage *page; - - if (position > priv->children->len - 1) + if (position >= priv->children->len) return NULL; page = g_ptr_array_index (priv->children, position); @@ -642,7 +641,7 @@ gtk_stack_pages_is_selected (GtkSelectionModel *model, GtkStackPrivate *priv = gtk_stack_get_instance_private (pages->stack); GtkStackPage *page; - if (position > priv->children->len - 1) + if (position >= priv->children->len) return FALSE; page = g_ptr_array_index (priv->children, position); @@ -664,6 +663,9 @@ gtk_stack_pages_select_item (GtkSelectionModel *model, GtkStackPrivate *priv = gtk_stack_get_instance_private (pages->stack); GtkStackPage *page; + if (position >= priv->children->len) + return FALSE; + page = g_ptr_array_index (priv->children, position); set_visible_child (pages->stack, page, priv->transition_type, priv->transition_duration); @@ -813,7 +815,7 @@ gtk_stack_accessible_get_first_accessible_child (GtkAccessible *accessible) if (priv->children->len > 0) page_accessible = GTK_ACCESSIBLE (g_object_ref (g_ptr_array_index (priv->children, 0))); - + return page_accessible; } -- 2.30.2