Blame SOURCES/tigervnc-1.3.1-CVE-2014-8240.patch

be441b
diff --git a/unix/x0vncserver/Image.cxx b/unix/x0vncserver/Image.cxx
be441b
index f998c6a..fb9dbd4 100644
be441b
--- a/unix/x0vncserver/Image.cxx
be441b
+++ b/unix/x0vncserver/Image.cxx
be441b
@@ -80,6 +80,14 @@ void Image::Init(int width, int height)
be441b
   xim = XCreateImage(dpy, vis, DefaultDepth(dpy, DefaultScreen(dpy)),
be441b
                      ZPixmap, 0, 0, width, height, BitmapPad(dpy), 0);
be441b
be441b
+  if (xim->bytes_per_line <= 0 ||
be441b
+      xim->height <= 0 ||
be441b
+      xim->height >= INT_MAX / xim->bytes_per_line) {
be441b
+    vlog.error("Invalid display size");
be441b
+    XDestroyImage(xim);
be441b
+    exit(1);
be441b
+  }
be441b
+
be441b
   xim->data = (char *)malloc(xim->bytes_per_line * xim->height);
be441b
   if (xim->data == NULL) {
be441b
     vlog.error("malloc() failed");
be441b
@@ -256,6 +264,17 @@ void ShmImage::Init(int width, int height, const XVisualInfo *vinfo)
be441b
     return;
be441b
   }
be441b
be441b
+  if (xim->bytes_per_line <= 0 ||
be441b
+      xim->height <= 0 ||
be441b
+      xim->height >= INT_MAX / xim->bytes_per_line) {
be441b
+    vlog.error("Invalid display size");
be441b
+    XDestroyImage(xim);
be441b
+    xim = NULL;
be441b
+    delete shminfo;
be441b
+    shminfo = NULL;
be441b
+    return;
be441b
+  }
be441b
+
be441b
   shminfo->shmid = shmget(IPC_PRIVATE,
be441b
                           xim->bytes_per_line * xim->height,
be441b
                           IPC_CREAT|0777);
be441b
diff --git a/vncviewer/PlatformPixelBuffer.cxx b/vncviewer/PlatformPixelBuffer.cxx
be441b
index a2b506d..9266d9f 100644
be441b
--- a/vncviewer/PlatformPixelBuffer.cxx
be441b
+++ b/vncviewer/PlatformPixelBuffer.cxx
be441b
@@ -49,6 +49,15 @@ PlatformPixelBuffer::PlatformPixelBuffer(int width, int height) :
be441b
     if (!xim)
be441b
       throw rdr::Exception("XCreateImage");
be441b
be441b
+    if (xim->bytes_per_line <= 0 ||
be441b
+       xim->height <= 0 ||
be441b
+       xim->height >= INT_MAX / xim->bytes_per_line) {
be441b
+      if (xim)
be441b
+       XDestroyImage(xim);
be441b
+      xim = NULL;
be441b
+      throw rdr::Exception("Invalid display size");
be441b
+    }
be441b
+
be441b
     xim->data = (char*)malloc(xim->bytes_per_line * xim->height);
be441b
     if (!xim->data)
be441b
       throw rdr::Exception("malloc");
be441b
@@ -152,6 +161,16 @@ bool PlatformPixelBuffer::setupShm()
be441b
   if (!xim)
be441b
     goto free_shminfo;
be441b
be441b
+  if (xim->bytes_per_line <= 0 ||
be441b
+      xim->height <= 0 ||
be441b
+      xim->height >= INT_MAX / xim->bytes_per_line) {
be441b
+    XDestroyImage(xim);
be441b
+    xim = NULL;
be441b
+    delete shminfo;
be441b
+    shminfo = NULL;
be441b
+    throw rdr::Exception("Invalid display size");
be441b
+  }
be441b
+
be441b
   shminfo->shmid = shmget(IPC_PRIVATE,
be441b
                           xim->bytes_per_line * xim->height,
be441b
                           IPC_CREAT|0600);