GNOME Bugzilla – Bug 783624
gtk_init_with_args returns FALSE without fillin in the GError
Last modified: 2017-07-21 15:57:41 UTC
We've got a number of bug reports up- and downstream, where gnome-terminal-server crashes when parsing the arguments, which I've finally tracked down to gtk+. Steps to repro: $ DISPLAY= XDG_RUNTIME_DIR= /usr/libexec/gnome-terminal-server Unable to init server: Verbindung ist gescheitert:Connection refused Segmentation fault (Speicherabzug geschrieben) Cause: gnome-terminal-server calls gtk_init_with_args(). The call returns FALSE but violates the API contract by not setting the GError out param, when opening a display fails for all backends: --- done: if (GDK_PRIVATE_CALL (gdk_display_open_default) () != NULL) { if (gtk_get_debug_flags () & GTK_DEBUG_INTERACTIVE) gtk_window_set_interactive_debugging (TRUE); return TRUE; } return FALSE; --- Clearly, it needs to use g_set_error() before the |return FALSE;|.
fwiw, the function has behaved in exactly the same way for a very long time, and the documentation never says that returning FALSE implies that error is set. The error is likewise not set in the check_setugid() case.
Are you really going to argue that the pattern 'gboolean foo (...., GError**) function returns either TRUE, or FALSE with the error filled' in is not the overall API pattern in gnome, and that I should study the source or docs closely to spot them not mentioning the filled-in error? Not setting the error in the setugid case is also a bug, IMO. Also, AFAICT this isn't a 'forever' bug but introduced in commit 8a7d0ab4813457088335685e956313afbd1d65a1 (bug 771959) which changes the call from gtk_get_option_group(TRUE) (which does set the error in case opening the default display fails) to FALSE.
(In reply to Christian Persch from comment #2) > Are you really going to argue that the pattern 'gboolean foo (...., > GError**) function returns either TRUE, or FALSE with the error filled' in > is not the overall API pattern in gnome, and that I should study the source > or docs closely to spot them not mentioning the filled-in error? No, I'm not going to argue that. It is certainly a common pattern.
(In reply to Matthias Clasen from comment #1) > The error is likewise not set in the check_setugid() case. That check_setugid function is interesting. :) It either exits, or always returns TRUE. I wonder if its return type should be void. But in practice, the way the code is today, the !check_setugid() case doesn't matter.
(In reply to Christian Persch from comment #2) > Also, AFAICT this isn't a 'forever' bug but introduced in commit > 8a7d0ab4813457088335685e956313afbd1d65a1 (bug 771959) which changes the call > from gtk_get_option_group(TRUE) (which does set the error in case opening > the default display fails) to FALSE. Thanks for bisecting this! I attached a few patches to bug 771959, and I have one coming to fix the unset GError **. However, I don't understand what the original intent of bug 771959 was. Let's mark this as a duplicate of bug 771959 to simplify the paper trail. *** This bug has been marked as a duplicate of bug 771959 ***