Bug 1397918 - don't use versions of libxcb before 1.11.1. r=karlt
authorLee Salzman <lsalzman@mozilla.com>
Fri, 22 Sep 2017 00:10:35 -0400
changeset 668890 a33c563d5428ddc49e06d802ea04fbea69999e40
parent 668889 0b39d5cbf3d1cf23fc162fb8b4e9261cbb3d6521
child 668891 e2b1cd9fd4a66fc932d8f74cfe2b38c55b9a7a1e
push id81146
push userbmo:topwu.tw@gmail.com
push dateFri, 22 Sep 2017 05:24:51 +0000
reviewerskarlt
bugs1397918
milestone58.0a1
Bug 1397918 - don't use versions of libxcb before 1.11.1. r=karlt MozReview-Commit-ID: Ec8ZhCBlPj2
widget/nsShmImage.cpp
--- a/widget/nsShmImage.cpp
+++ b/widget/nsShmImage.cpp
@@ -9,16 +9,17 @@
 #ifdef MOZ_HAVE_SHMIMAGE
 #include "mozilla/X11Util.h"
 #include "mozilla/gfx/gfxVars.h"
 #include "mozilla/ipc/SharedMemory.h"
 #include "gfxPlatform.h"
 #include "nsPrintfCString.h"
 #include "nsTArray.h"
 
+#include <dlfcn.h>
 #include <errno.h>
 #include <string.h>
 #include <sys/ipc.h>
 #include <sys/shm.h>
 
 extern "C" {
 #include <X11/ImUtil.h>
 }
@@ -114,16 +115,27 @@ bool
 nsShmImage::InitExtension()
 {
   if (gShmInitialized) {
     return gShmAvailable;
   }
 
   gShmInitialized = true;
 
+  // Bugs 1397918, 1293474 - race condition in libxcb fixed upstream as of
+  // version 1.11. Since we can't query libxcb's version directly, the only
+  // other option is to check for symbols that were added after 1.11.
+  // xcb_discard_reply64 was added in 1.11.1, so check for existence of
+  // that to verify we are using a version of libxcb with the bug fixed.
+  // Otherwise, we can't risk using libxcb due to aforementioned crashes.
+  if (!dlsym(RTLD_DEFAULT, "xcb_discard_reply64")) {
+    gShmAvailable = false;
+    return false;
+  }
+
   const xcb_query_extension_reply_t* extReply;
   extReply = xcb_get_extension_data(mConnection, &xcb_shm_id);
   if (!extReply || !extReply->present) {
     gShmAvailable = false;
     return false;
   }
 
   xcb_shm_query_version_reply_t* shmReply = xcb_shm_query_version_reply(