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 655366 - missing GSettings schemas lead to obscure crashes
missing GSettings schemas lead to obscure crashes
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gsettings
2.30.x
Other Linux
: Normal critical
: ---
Assigned To: Allison Karlitskaya (desrt)
gtkdev
: 655427 655807 659604 659832 661222 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2011-07-26 18:27 UTC by Pedro Villavicencio
Modified: 2011-10-20 09:39 UTC
See Also:
GNOME target: ---
GNOME version: 3.1/3.2


Attachments
Avoid unreffing if variant is NULL (1.89 KB, patch)
2011-10-03 13:38 UTC, Rodney Dawes
none Details | Review
Avoid unref if variant is NULL (404 bytes, patch)
2011-10-03 14:01 UTC, Rodney Dawes
rejected Details | Review
Update patch that uses g_return_if_fail instead (406 bytes, patch)
2011-10-03 14:59 UTC, Rodney Dawes
committed Details | Review

Description Pedro Villavicencio 2011-07-26 18:27:54 UTC
this report has been filed here:

https://bugs.launchpad.net/ubuntu/+source/gnome-terminal/+bug/816299

backtrace:

".

Thread 1 (Thread 5134)

  • #0 g_variant_unref
    at /build/buildd/glib2.0-2.29.14/./glib/gvariant-core.c line 617
  • #1 g_settings_get
    at /build/buildd/glib2.0-2.29.14/./gio/gsettings.c line 1623
  • #2 terminal_app_system_font_notify_cb
    at terminal-app.c line 977
  • #3 terminal_app_init
    at terminal-app.c line 1390
  • #4 g_type_create_instance
    at /build/buildd/glib2.0-2.29.14/./gobject/gtype.c line 1885
  • #5 g_object_constructor
    at /build/buildd/glib2.0-2.29.14/./gobject/gobject.c line 1629
  • #6 g_object_newv
    at /build/buildd/glib2.0-2.29.14/./gobject/gobject.c line 1412
  • #7 g_object_new
    at /build/buildd/glib2.0-2.29.14/./gobject/gobject.c line 1322
  • #8 terminal_app_get
    at terminal-app.c line 1660
  • #9 name_acquired_cb
    at terminal.c line 275
  • #10 actually_do_call
    at /build/buildd/glib2.0-2.29.14/./gio/gdbusnameowning.c line 165
  • #11 do_call
    at /build/buildd/glib2.0-2.29.14/./gio/gdbusnameowning.c line 213
  • #12 call_acquired_handler
    at /build/buildd/glib2.0-2.29.14/./gio/gdbusnameowning.c line 224
  • #13 request_name_cb
    at /build/buildd/glib2.0-2.29.14/./gio/gdbusnameowning.c line 311
  • #14 g_simple_async_result_complete
    at /build/buildd/glib2.0-2.29.14/./gio/gsimpleasyncresult.c line 749
  • #15 g_dbus_connection_call_done
    at /build/buildd/glib2.0-2.29.14/./gio/gdbusconnection.c line 5043
  • #16 g_simple_async_result_complete
    at /build/buildd/glib2.0-2.29.14/./gio/gsimpleasyncresult.c line 749
  • #17 complete_in_idle_cb
    at /build/buildd/glib2.0-2.29.14/./gio/gsimpleasyncresult.c line 761
  • #18 g_idle_dispatch
    at /build/buildd/glib2.0-2.29.14/./glib/gmain.c line 4867
  • #19 g_main_dispatch
    at /build/buildd/glib2.0-2.29.14/./glib/gmain.c line 2500
  • #20 g_main_context_dispatch
    at /build/buildd/glib2.0-2.29.14/./glib/gmain.c line 3083
  • #21 g_main_context_iterate
    at /build/buildd/glib2.0-2.29.14/./glib/gmain.c line 3161
  • #22 g_main_loop_run
    at /build/buildd/glib2.0-2.29.14/./glib/gmain.c line 3369
  • #23 gtk_main
    at /build/buildd/gtk+3.0-3.1.10/./gtk/gtkmain.c line 1367
  • #24 main
    at terminal.c line 594

Comment 1 Christian Persch 2011-07-26 18:52:58 UTC
-> gsettings
Comment 2 Allison Karlitskaya (desrt) 2011-07-26 20:55:43 UTC
The only way that this variable can be NULL is if GSettings has failed an assertion already due to an invalid key -- that would point to a bug in the user of GSettings.

That said, we could deal with this error case more gracefully as well...
Comment 3 Christian Persch 2011-07-26 21:34:00 UTC
The key definitely exists in that schema (from gsettings-desktop-schemas) (otherwise there'd be tons of dups already).

The .xsession-errors file available on lp that comment 0 failed to link to doesn't contain any gsettings criticals.

You can probably just close this one as unreproducible and blame some freak ubuntu weirdness :)
Comment 4 Rodney Dawes 2011-10-03 13:22:14 UTC
*** Bug 655807 has been marked as a duplicate of this bug. ***
Comment 5 Rodney Dawes 2011-10-03 13:22:47 UTC
*** Bug 659832 has been marked as a duplicate of this bug. ***
Comment 6 Rodney Dawes 2011-10-03 13:26:52 UTC
*** Bug 659604 has been marked as a duplicate of this bug. ***
Comment 7 Rodney Dawes 2011-10-03 13:27:01 UTC
*** Bug 655427 has been marked as a duplicate of this bug. ***
Comment 8 Rodney Dawes 2011-10-03 13:38:35 UTC
Created attachment 198086 [details] [review]
Avoid unreffing if variant is NULL

Not sure why gsettings wasn't doing this already. This is a simple patch that checks for NULL before the g_variant_unref() in every g_settings_get_ call other than g_settings_get_value (which is where the variant value comes from in all the other calls, and can return NULL).
Comment 9 Rodney Dawes 2011-10-03 14:01:20 UTC
Created attachment 198087 [details] [review]
Avoid unref if variant is NULL

Here is a much simpler patch. Don't know why I didn't just do this in the first place. :)
Comment 10 Allison Karlitskaya (desrt) 2011-10-03 14:11:45 UTC
Review of attachment 198087 [details] [review]:

It's an error to call g_variant_unref() on a NULL GVariant.  This is a very strong convention in GLib -- it applies also to GObject and pretty much everything else.
Comment 11 Allison Karlitskaya (desrt) 2011-10-03 14:12:33 UTC
Review of attachment 198086 [details] [review]:

This might be where the crash occurs, but the real bug is further up -- where the user created a GSettings object without the schema installed.

This patch just treats the symptom.
Comment 12 Allison Karlitskaya (desrt) 2011-10-03 14:22:32 UTC
commit 3106391694408877ebf6e8451146c5ac5d7bb017
Author: Ryan Lortie <desrt@desrt.ca>
Date:   Mon Oct 3 10:19:14 2011 -0400

    Revert "GSettings: don't abort on missing schemas"
    
    This reverts commit c841c2ce3fda6f754c88ae2c9099f36dff2f0814.
    
    This approach has been an unmitigated disaster.  We're getting all sorts
    of crashes due to functions that are returning NULL because they can't
    find the schema for the default value.  The people who get these crashes
    are then confused about the root cause of the problem and waste a lot of
    time trying to figure it out.
    
    Until we find a better solution, we should go back to what we had
    before.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=655366
Comment 13 Rodney Dawes 2011-10-03 14:59:44 UTC
Created attachment 198105 [details] [review]
Update patch that uses g_return_if_fail instead

Updated patch which only does g_return_if_fail inside g_variant_unref so we get criticals but avoid segfault in normal usage.
Comment 14 Allison Karlitskaya (desrt) 2011-10-03 15:02:55 UTC
Review of attachment 198105 [details] [review]:

commit to glib-2-30 please.
Comment 15 Rodney Dawes 2011-10-03 19:31:26 UTC
Should this not also go onto master?
Comment 16 Allison Karlitskaya (desrt) 2011-10-03 19:34:46 UTC
I've heard a rumour that you're attempting to use the fact that your program no longer crashes completely (and merely g_critical()s all over the place) to argue that it is now correct.  I disagree with that assertion.

I consider this patch to be treatment for the bad symptoms caused by the fact that GSettings doesn't abort on missing schemas on glib-2-30.  We no longer have that problem on master.
Comment 17 Rodney Dawes 2011-10-05 13:19:29 UTC
Rumors are just that. I'm suggesting that GValue is a public API and GSettings isn't the only thing to use it, and the correct behavior should be to critical rather than segfault if a NULL does get passed in. This patch fixes that to be the case.
Comment 18 Allison Karlitskaya (desrt) 2011-10-08 01:18:37 UTC
*** Bug 661222 has been marked as a duplicate of this bug. ***
Comment 19 Milan Bouchet-Valat 2011-10-20 09:39:10 UTC
(In reply to comment #16)
> I've heard a rumour that you're attempting to use the fact that your program no
> longer crashes completely (and merely g_critical()s all over the place) to
> argue that it is now correct.  I disagree with that assertion.
> 
> I consider this patch to be treatment for the bad symptoms caused by the fact
> that GSettings doesn't abort on missing schemas on glib-2-30.  We no longer
> have that problem on master.
I think Rodney is right. Now that we abort again on missing schemas, people won't be able to consider it correct and get hundreds of warnings: it will crash their programs.

So you can safely fix g_variant_unref() not to crash when passed NULL. g_object_unref() already does that (actually, it does even more, since it calls G_IS_OBJECT(), which is probably a good idea).