[Spice-devel] [PATCH spice 1/2] spicec-x11: Don't crash on apps sending bad atoms as TARGETS

Hans de Goede hdegoede at redhat.com
Wed Mar 23 09:18:50 PDT 2011


Some apps (bad xsel, bad!) send invalid Atoms in their TARGETS property,
causing spicec to exit because of an XError. This patch makes spicec survive
this scenario.

For more info on the xsel bug, see:
https://bugzilla.redhat.com/show_bug.cgi?id=690214
---
 client/x11/platform.cpp |   28 ++++++++++++++++------------
 1 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/client/x11/platform.cpp b/client/x11/platform.cpp
index 48d5a52..9fff947 100644
--- a/client/x11/platform.cpp
+++ b/client/x11/platform.cpp
@@ -180,6 +180,18 @@ public:
 static DefaultClipboardListener default_clipboard_listener;
 static Platform::ClipboardListener* clipboard_listener = &default_clipboard_listener;
 
+static void handle_x_errors_start(void)
+{
+    handle_x_error = True;
+    x_error_code = 0;
+}
+
+static int handle_x_errors_stop(void)
+{
+    handle_x_error = False;
+    return x_error_code;
+}
+
 static const char *atom_name(Atom atom)
 {
     const char *name;
@@ -188,7 +200,11 @@ static const char *atom_name(Atom atom)
         return "None";
 
     XLockDisplay(x_display);
+    handle_x_errors_start();
     name = XGetAtomName(x_display, atom);
+    if (handle_x_errors_stop()) {
+        name = "Bad Atom";
+    }
     XUnlockDisplay(x_display);
 
     return name;
@@ -317,18 +333,6 @@ Display* XPlatform::get_display()
     return x_display;
 }
 
-static void handle_x_errors_start(void)
-{
-    handle_x_error = True;
-    x_error_code = 0;
-}
-
-static int handle_x_errors_stop(void)
-{
-    handle_x_error = False;
-    return x_error_code;
-}
-
 bool XPlatform::is_x_shm_avail()
 {
     return x_shm_avail;
-- 
1.7.3.2



More information about the Spice-devel mailing list