gtk: fix NULL pointer dereference
authorAndy Holmes <andyholmes@gnome.org>
Mon, 13 Nov 2023 20:05:31 +0000 (12:05 -0800)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 17 Nov 2023 20:28:58 +0000 (15:28 -0500)
`gtk_window_get_default_size()` claims width/height are optional-out
arguments, but defers to `gtk_window_get_remembered_size()` which
may dereference a NULL-pointer.

Since `gtk_window_get_remembered_size()` is only called by
`gtk_window_get_default_size()`, collapse it into the latter
and perform the NULL check there.

gtk/gtkwindow.c

index 2eb94d6f7e09af09831f48da753153cc5acf23ea..b6864a6297bcb0c0991656db890c221aeb399611 100644 (file)
@@ -397,10 +397,6 @@ static int gtk_window_focus              (GtkWidget        *widget,
 static void gtk_window_move_focus         (GtkWidget         *widget,
                                            GtkDirectionType   dir);
 
-static void gtk_window_get_remembered_size (GtkWindow         *window,
-                                            int               *width,
-                                            int               *height);
-
 static void gtk_window_real_activate_default (GtkWindow         *window);
 static void gtk_window_real_activate_focus   (GtkWindow         *window);
 static void gtk_window_keys_changed          (GtkWindow         *window);
@@ -3718,9 +3714,15 @@ gtk_window_get_default_size (GtkWindow *window,
                             int       *width,
                             int       *height)
 {
+  GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
+
   g_return_if_fail (GTK_IS_WINDOW (window));
 
-  gtk_window_get_remembered_size (window, width, height);
+  if (width != NULL)
+    *width = priv->default_width;
+
+  if (height != NULL)
+    *height = priv->default_height;
 }
 
 static gboolean
@@ -4043,17 +4045,6 @@ gtk_window_unmap (GtkWidget *widget)
     gtk_widget_unmap (child);
 }
 
-static void
-gtk_window_get_remembered_size (GtkWindow *window,
-                                int       *width,
-                                int       *height)
-{
-  GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
-
-  *width = priv->default_width;
-  *height = priv->default_height;
-}
-
 static void
 check_scale_changed (GtkWindow *window)
 {