After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 778382 - gtk_css_static_style_get_default doesn't check for a null setting
gtk_css_static_style_get_default doesn't check for a null setting
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: .General
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
: 783171 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2017-02-09 09:27 UTC by Carlo Caione
Modified: 2017-09-12 15:06 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gtk_css_static_style_get_default doesn't check for a null setting (2.15 KB, patch)
2017-02-09 09:27 UTC, Carlo Caione
none Details | Review
gtksettings: Add a debug message if there is no default GtkSettings (970 bytes, patch)
2017-02-09 17:18 UTC, Philip Withnall
none Details | Review
gtksettings: Add a debug message if there is no default GtkSettings (995 bytes, patch)
2017-02-09 19:41 UTC, Philip Withnall
committed Details | Review

Description Carlo Caione 2017-02-09 09:27:03 UTC
Created attachment 345296 [details] [review]
gtk_css_static_style_get_default doesn't check for a null setting

On my platform gnome-session-failed is segfaulting with this trace:

Core was generated by `/usr/lib/gnome-session/gnome-session-failed'.
Program terminated with signal SIGSEGV, Segmentation fault.
  • #0 _gtk_style_provider_private_get_settings
    at /usr/src/packages/BUILD/gtk+3.0-3.22.4+dev30.10aaa4d/./gtk/gtkstyleproviderprivate.c line 123
  • #0 _gtk_style_provider_private_get_settings
    at /usr/src/packages/BUILD/gtk+3.0-3.22.4+dev30.10aaa4d/./gtk/gtkstyleproviderprivate.c line 123
  • #1 gtk_css_value_initial_compute
    at /usr/src/packages/BUILD/gtk+3.0-3.22.4+dev30.10aaa4d/./gtk/gtkcssinitialvalue.c line 52
  • #2 gtk_css_static_style_compute_value
    at /usr/src/packages/BUILD/gtk+3.0-3.22.4+dev30.10aaa4d/./gtk/gtkcssstaticstyle.c line 237
  • #3 _gtk_css_lookup_resolve
    at /usr/src/packages/BUILD/gtk+3.0-3.22.4+dev30.10aaa4d/./gtk/gtkcsslookup.c line 122
  • #4 gtk_css_static_style_new_compute
    at /usr/src/packages/BUILD/gtk+3.0-3.22.4+dev30.10aaa4d/./gtk/gtkcssstaticstyle.c line 195
  • #5 gtk_css_static_style_get_default
    at /usr/src/packages/BUILD/gtk+3.0-3.22.4+dev30.10aaa4d/./gtk/gtkcssstaticstyle.c line 164
  • #6 gtk_css_node_init
    at /usr/src/packages/BUILD/gtk+3.0-3.22.4+dev30.10aaa4d/./gtk/gtkcssnode.c line 663
  • #7 g_type_create_instance
    from /lib/arm-linux-gnueabihf/libgobject-2.0.so.0
  • #8 ??
    from /lib/arm-linux-gnueabihf/libgobject-2.0.so.0

The problem seems to be gtk_css_static_style_get_default() failing to handle the fact that gtk_settings_get_default() can return NULL.
In attachment the proposed patch.
Comment 1 Emmanuele Bassi (:ebassi) 2017-02-09 10:12:28 UTC
The only reason why gtk_settings_get_default() returns NULL is that there's no default GdkDisplay, which means there's no display connection, which means there really are no settings. We don't generally check the return value of gtk_settings_get_default().

The only reason why gtk_settings_get_default() even can return NULL is because a bunch of old code ported from GTK+ 2.x has the tendency to call gtk_settings_get_default() without initializing GTK, but if you get this far into the style system then you must have called gtk_init() and have a default GdkDisplay, which means having a default GtkSettings instance.
Comment 2 Philip Withnall 2017-02-09 10:47:52 UTC
(In reply to Emmanuele Bassi (:ebassi) from comment #1)
> The only reason why gtk_settings_get_default() returns NULL is that there's
> no default GdkDisplay, which means there's no display connection, which
> means there really are no settings. We don't generally check the return
> value of gtk_settings_get_default().
> 
> The only reason why gtk_settings_get_default() even can return NULL is
> because a bunch of old code ported from GTK+ 2.x has the tendency to call
> gtk_settings_get_default() without initializing GTK, but if you get this far
> into the style system then you must have called gtk_init() and have a
> default GdkDisplay, which means having a default GtkSettings instance.

Perhaps the documentation for gdk_settings_get_default() could be improved to mention this? Should perhaps also add some assertions or critical warnings on each call to gdk_settings_get_default() in bits of GTK+ which really should have a display to work properly.
Comment 3 Emmanuele Bassi (:ebassi) 2017-02-09 10:57:19 UTC
The documentation for `gtk_settings_get_default()` already says:

```
 * Returns: (nullable) (transfer none): a #GtkSettings object. If there is
 * no default screen, then returns %NULL.
```

But it would be okay by me to add a g_debug() note that says that you attempted to get the default settings singleton without a GdkDisplay.

I'm more dubious about adding assertions because that bit us in the past with applications calling GTK API that "was safe to call in a previous version" without calling gtk_init().
Comment 4 Philip Withnall 2017-02-09 17:18:18 UTC
Created attachment 345352 [details] [review]
gtksettings: Add a debug message if there is no default GtkSettings

Make it slightly more obvious when things are about to slide sideways
because a NULL GtkSettings has been returned to a caller. This is a
valid return value, but is rarely handled correctly.
Comment 5 Philip Withnall 2017-02-09 19:41:22 UTC
Created attachment 345368 [details] [review]
gtksettings: Add a debug message if there is no default GtkSettings

Make it slightly more obvious when things are about to slide sideways
because a NULL GtkSettings has been returned to a caller. This is a
valid return value, but is rarely handled correctly.
Comment 6 Timm Bäder 2017-05-03 13:46:54 UTC
Is a g_debug here really useful? Even if you compile with --enable-debug, g_debug messages only appear if you also use G_MESSAGES_DEBUG=Gtk.
Comment 7 Philip Withnall 2017-05-03 14:01:09 UTC
(In reply to Timm Bäder from comment #6)
> Is a g_debug here really useful? Even if you compile with --enable-debug,
> g_debug messages only appear if you also use G_MESSAGES_DEBUG=Gtk.

…which is what I would do if I were debugging a problem. Up to you.
Comment 8 Timm Bäder 2017-05-28 15:37:45 UTC
*** Bug 783171 has been marked as a duplicate of this bug. ***
Comment 9 Philip Withnall 2017-09-12 15:03:04 UTC
Review of attachment 345368 [details] [review]:

Reviewed by Timm on IRC: “Meh, don't really care. You can push that”.
Comment 10 Philip Withnall 2017-09-12 15:05:58 UTC
Attachment 345368 [details] pushed as 80b10aa - gtksettings: Add a debug message if there is no default GtkSettings