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

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