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 783624 - gtk_init_with_args returns FALSE without fillin in the GError
gtk_init_with_args returns FALSE without fillin in the GError
Status: RESOLVED DUPLICATE of bug 771959
Product: gtk+
Classification: Platform
Component: .General
3.22.x
Other All
: Normal critical
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2017-06-10 07:41 UTC by Christian Persch
Modified: 2017-07-21 15:57 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Christian Persch 2017-06-10 07:41:20 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;|.
Comment 1 Matthias Clasen 2017-06-14 01:50:44 UTC
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.
Comment 2 Christian Persch 2017-06-14 15:11:50 UTC
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.
Comment 3 Matthias Clasen 2017-06-15 19:58:02 UTC
(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.
Comment 4 Debarshi Ray 2017-07-21 15:53:22 UTC
(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.
Comment 5 Debarshi Ray 2017-07-21 15:57:41 UTC
(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 ***