[gtk: 1/2] gtkstack: fix null pointer dereference



commit 44655932c4be04cfb6010929df9831e9c04a8ce1
Author: Hugo Lefeuvre <hle debian org>
Date:   Wed Sep 26 16:59:59 2018 -0400

    gtkstack: fix null pointer dereference
    
    The gtk_stack_snapshot_slide() function dereferences the
    last_visible_child pointer without proper != NULL ckeck. This might
    result in NULL pointer dereference and crash if last_visible_child is
    invalid.
    
    Add a != NULL check before dereferencing the pointer.

 gtk/gtkstack.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkstack.c b/gtk/gtkstack.c
index a3d36a8603..f74894b8e1 100644
--- a/gtk/gtkstack.c
+++ b/gtk/gtkstack.c
@@ -1910,11 +1910,14 @@ gtk_stack_snapshot_slide (GtkWidget   *widget,
           break;
         }
 
-      if (gtk_widget_get_valign (priv->last_visible_child->widget) == GTK_ALIGN_END &&
-          priv->last_visible_widget_height > height)
-        y -= priv->last_visible_widget_height - height;
-      else if (gtk_widget_get_valign (priv->last_visible_child->widget) == GTK_ALIGN_CENTER)
-        y -= (priv->last_visible_widget_height - height) / 2;
+      if (priv->last_visible_child != NULL)
+        {
+          if (gtk_widget_get_valign (priv->last_visible_child->widget) == GTK_ALIGN_END &&
+              priv->last_visible_widget_height > height)
+            y -= priv->last_visible_widget_height - height;
+          else if (gtk_widget_get_valign (priv->last_visible_child->widget) == GTK_ALIGN_CENTER)
+            y -= (priv->last_visible_widget_height - height) / 2;
+        }
 
       gtk_snapshot_offset (snapshot, x, y);
       gtk_snapshot_append_node (snapshot, priv->last_visible_node);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]