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

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