Blame SOURCES/LibVNCServer-0.9.10-CVE-2014-6051.patch

e0f39d
commit 045a044e8ae79db9244593fbce154cdf6e843273
e0f39d
Author: newsoft <newsoft@MacBook-Air-de-newsoft-2.local>
e0f39d
Date:   Fri Aug 15 16:31:13 2014 +0200
e0f39d
e0f39d
    Fix integer overflow in MallocFrameBuffer()
e0f39d
    
e0f39d
    Promote integers to uint64_t to avoid integer overflow issue during
e0f39d
    frame buffer allocation for very large screen sizes
e0f39d
e0f39d
diff --git a/libvncclient/vncviewer.c b/libvncclient/vncviewer.c
e0f39d
index 3b16a6f..24bc6f8 100644
e0f39d
--- a/libvncclient/vncviewer.c
e0f39d
+++ b/libvncclient/vncviewer.c
e0f39d
@@ -82,9 +82,27 @@ static char* ReadPassword(rfbClient* client) {
e0f39d
 #endif
e0f39d
 }
e0f39d
 static rfbBool MallocFrameBuffer(rfbClient* client) {
e0f39d
+uint64_t allocSize;
e0f39d
+
e0f39d
   if(client->frameBuffer)
e0f39d
     free(client->frameBuffer);
e0f39d
-  client->frameBuffer=malloc(client->width*client->height*client->format.bitsPerPixel/8);
e0f39d
+
e0f39d
+  /* SECURITY: promote 'width' into uint64_t so that the multiplication does not overflow
e0f39d
+     'width' and 'height' are 16-bit integers per RFB protocol design
e0f39d
+     SIZE_MAX is the maximum value that can fit into size_t
e0f39d
+  */
e0f39d
+  allocSize = (uint64_t)client->width * client->height * client->format.bitsPerPixel/8;
e0f39d
+
e0f39d
+  if (allocSize >= SIZE_MAX) {
e0f39d
+    rfbClientErr("CRITICAL: cannot allocate frameBuffer, requested size is too large\n");
e0f39d
+    return FALSE;
e0f39d
+  }
e0f39d
+
e0f39d
+  client->frameBuffer=malloc( (size_t)allocSize );
e0f39d
+
e0f39d
+  if (client->frameBuffer == NULL)
e0f39d
+    rfbClientErr("CRITICAL: frameBuffer allocation failed, requested size too large or not enough memory?\n");
e0f39d
+
e0f39d
   return client->frameBuffer?TRUE:FALSE;
e0f39d
 }
e0f39d