GNOME Bugzilla – Bug 740613
XConvertSelection crashes Gtk+ apps
Last modified: 2015-01-25 00:53:40 UTC
Forwarded from https://bugs.launchpad.net/ubuntu/+source/gnome-terminal/+bug/1395250 Calling XConvertSelection() in an app crashes whichever Gtk+ app that has the selection. [The original report is about gnome-terminal, but pretty much any Gtk+ app can be crashed. The original report is on Ubuntu 12.04, but I can also reproduce on 14.10 (Gtk+ 3.12.2).] Code to trigger the crash: // gcc -o foo foo.c -lX11 && ./foo #include <X11/Xlib.h> int main() { Display* dpy = XOpenDisplay(0); Atom selection = XInternAtom(dpy, "PRIMARY", False); Atom target = XInternAtom(dpy, "STRING", False); Window table = RootWindow(dpy, 0); XConvertSelection(dpy, selection, target, None, table, CurrentTime); XSync(dpy, 0); return 0; }
Hi (Egmont alerted me to this via the Ubuntu bug) The patch (732af31) doesn't fix it for me, 3.14.7 which has the patch too or git master. Does it for you? 1. Open gedit 2. Type some text 3. Highlight it using the mouse 4. Run the test program above in a terminal gedit crashes
It did for me, otherwise I wouldn't have closed the bug. Maybe there's something more to fix, then. In any case, the behavior of the code snipplet was considered obsolete at the time the ICCCM was written (a generation ago), so if you find such code in the wild, it is truly behind the times...
Bug 743115 was reported yesterday which is persumably the same. Supertuxkart (or a library it uses) uses this snippet. Supertux (or the lib it uses) could/should migrate from the obsolete methods to current ones, that'd be a great workaround. But as long as that method is not removed for good, Gtk+ should not crash either.
XConvertSelection() function is used also in SDL2 library. It means that it's used by quite a lot games and applications, also commercial.
Using XConvertSelection is fine. Whats obsolete is passing None as the third argument.
As I understend create an atom should be fine? Atom selection = XInternAtom(display, "STK_SELECTION", False); XConvertSelection (display, X_ATOM_CLIPBOARD, XA_STRING, selection, ownerWindow, CurrentTime); instead of XConvertSelection (display, X_ATOM_CLIPBOARD, XA_STRING, None, ownerWindow, CurrentTime);
*** Bug 743115 has been marked as a duplicate of this bug. ***
Created attachment 295109 [details] gdb backtrace from gedit crash on paste I originally wrote this to the duplicate bug 743115: Pasting (Ctrl+V) into supertuxkart crashes the application I'm pasting from. It seems to be the same bug discussed here. I've tried with the git version of gtk and still get a crash and this error message: (gedit:804): Gdk-ERROR **: The program 'gedit' received an X Window System error. This probably reflects a bug in the program. The error was 'BadAtom (invalid Atom parameter)'. (Details: serial 5602 error_code 5 request_code 18 (core protocol) minor_code 0) (Note to programmers: normally, X errors are reported asynchronously; that is, you will receive the error a while after causing it. To debug your program, run it with the GDK_SYNCHRONIZE environment variable to change this behavior. You can then get a meaningful backtrace from your debugger if you break on the gdk_x_error() function.) [1] + trace trap (core dumped) gedit Only gedit crashes, not supertuxkart or the terminal. I'm attaching a gdb backtrace from doing what the error message says.