7c7df81
--- xorg-server-1.1.1/Xext/sampleEVI.c.cve-2007-6429	2006-07-05 14:31:36.000000000 -0400
7c7df81
+++ xorg-server-1.1.1/Xext/sampleEVI.c	2008-01-18 14:15:44.000000000 -0500
7c7df81
@@ -36,6 +36,13 @@
7c7df81
 #include <X11/extensions/XEVIstr.h>
7c7df81
 #include "EVIstruct.h"
7c7df81
 #include "scrnintstr.h"
7c7df81
+
7c7df81
+#if HAVE_STDINT_H
7c7df81
+#include <stdint.h>
7c7df81
+#elif !defined(INT_MAX)
7c7df81
+#define INT_MAX 0x7fffffff
7c7df81
+#endif
7c7df81
+
7c7df81
 static int sampleGetVisualInfo(
7c7df81
     VisualID32 *visual,
7c7df81
     int n_visual,
7c7df81
@@ -44,24 +51,36 @@
7c7df81
     VisualID32 **conflict_rn,
7c7df81
     int *n_conflict_rn)
7c7df81
 {
7c7df81
-    int max_sz_evi = n_visual * sz_xExtendedVisualInfo * screenInfo.numScreens;
7c7df81
+    unsigned int max_sz_evi;
7c7df81
     VisualID32 *temp_conflict;
7c7df81
     xExtendedVisualInfo *evi;
7c7df81
-    int max_visuals = 0, max_sz_conflict, sz_conflict = 0;
7c7df81
+    unsigned int max_visuals = 0, max_sz_conflict, sz_conflict = 0;
7c7df81
     register int visualI, scrI, sz_evi = 0, conflictI, n_conflict;
7c7df81
-    *evi_rn = evi = (xExtendedVisualInfo *)xalloc(max_sz_evi);
7c7df81
-    if (!*evi_rn)
7c7df81
-         return BadAlloc;
7c7df81
+
7c7df81
+    if (n_visual > UINT32_MAX/(sz_xExtendedVisualInfo * screenInfo.numScreens))
7c7df81
+	return BadAlloc;
7c7df81
+    max_sz_evi = n_visual * sz_xExtendedVisualInfo * screenInfo.numScreens;
7c7df81
+    
7c7df81
     for (scrI = 0; scrI < screenInfo.numScreens; scrI++) {
7c7df81
         if (screenInfo.screens[scrI]->numVisuals > max_visuals)
7c7df81
             max_visuals = screenInfo.screens[scrI]->numVisuals;
7c7df81
     }
7c7df81
+
7c7df81
+    if (n_visual > UINT32_MAX/(sz_VisualID32 * screenInfo.numScreens 
7c7df81
+			       * max_visuals)) 
7c7df81
+	return BadAlloc;
7c7df81
     max_sz_conflict = n_visual * sz_VisualID32 * screenInfo.numScreens * max_visuals;
7c7df81
+
7c7df81
+    *evi_rn = evi = (xExtendedVisualInfo *)xalloc(max_sz_evi);
7c7df81
+    if (!*evi_rn)
7c7df81
+         return BadAlloc;
7c7df81
+
7c7df81
     temp_conflict = (VisualID32 *)xalloc(max_sz_conflict);
7c7df81
     if (!temp_conflict) {
7c7df81
         xfree(*evi_rn);
7c7df81
         return BadAlloc;
7c7df81
     }
7c7df81
+
7c7df81
     for (scrI = 0; scrI < screenInfo.numScreens; scrI++) {
7c7df81
         for (visualI = 0; visualI < n_visual; visualI++) {
7c7df81
 	    evi[sz_evi].core_visual_id = visual[visualI];
7c7df81
--- xorg-server-1.1.1/Xext/EVI.c.cve-2007-6429	2006-07-05 14:31:36.000000000 -0400
7c7df81
+++ xorg-server-1.1.1/Xext/EVI.c	2008-01-18 14:15:44.000000000 -0500
7c7df81
@@ -36,6 +36,7 @@
7c7df81
 #include <X11/extensions/XEVIstr.h>
7c7df81
 #include "EVIstruct.h"
7c7df81
 #include "modinit.h"
7c7df81
+#include "scrnintstr.h"
7c7df81
 
7c7df81
 #if 0
7c7df81
 static unsigned char XEVIReqCode = 0;
7c7df81
@@ -89,10 +90,22 @@
7c7df81
 {
7c7df81
     REQUEST(xEVIGetVisualInfoReq);
7c7df81
     xEVIGetVisualInfoReply rep;
7c7df81
-    int n, n_conflict, n_info, sz_info, sz_conflict;
7c7df81
+    int i, n, n_conflict, n_info, sz_info, sz_conflict;
7c7df81
     VisualID32 *conflict;
7c7df81
+    unsigned int total_visuals = 0;
7c7df81
     xExtendedVisualInfo *eviInfo;
7c7df81
     int status;
7c7df81
+
7c7df81
+    /*
7c7df81
+     * do this first, otherwise REQUEST_FIXED_SIZE can overflow.  we assume
7c7df81
+     * here that you don't have more than 2^32 visuals over all your screens;
7c7df81
+     * this seems like a safe assumption.
7c7df81
+     */
7c7df81
+    for (i = 0; i < screenInfo.numScreens; i++)
7c7df81
+	total_visuals += screenInfo.screens[i]->numVisuals;
7c7df81
+    if (stuff->n_visual > total_visuals)
7c7df81
+	return BadValue;
7c7df81
+
7c7df81
     REQUEST_FIXED_SIZE(xEVIGetVisualInfoReq, stuff->n_visual * sz_VisualID32);
7c7df81
     status = eviPriv->getVisualInfo((VisualID32 *)&stuff[1], (int)stuff->n_visual,
7c7df81
 		&eviInfo, &n_info, &conflict, &n_conflict);
7c7df81
--- xorg-server-1.1.1/Xext/shm.c.cve-2007-6429	2006-07-05 14:31:36.000000000 -0400
7c7df81
+++ xorg-server-1.1.1/Xext/shm.c	2008-01-18 14:19:28.000000000 -0500
32286e4
@@ -725,6 +725,8 @@
32286e4
     int i, j, result;
32286e4
     ShmDescPtr shmdesc;
32286e4
     REQUEST(xShmCreatePixmapReq);
32286e4
+    unsigned int width, height, depth;
32286e4
+    unsigned long size;
32286e4
     PanoramiXRes *newPix;
32286e4
 
32286e4
     REQUEST_SIZE_MATCH(xShmCreatePixmapReq);
7c7df81
@@ -734,11 +736,18 @@
32286e4
     LEGAL_NEW_RESOURCE(stuff->pid, client);
32286e4
     VERIFY_GEOMETRABLE(pDraw, stuff->drawable, client);
32286e4
     VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client);
32286e4
-    if (!stuff->width || !stuff->height)
32286e4
+
32286e4
+    width = stuff->width;
32286e4
+    height = stuff->height;
32286e4
+    depth = stuff->depth;
32286e4
+    if (!width || !height || !depth)
32286e4
     {
32286e4
 	client->errorValue = 0;
32286e4
         return BadValue;
32286e4
     }
32286e4
+    if (width > 32767 || height > 32767)
32286e4
+        return BadAlloc;
32286e4
+
32286e4
     if (stuff->depth != 1)
32286e4
     {
32286e4
         pDepth = pDraw->pScreen->allowedDepths;
7c7df81
@@ -748,10 +757,19 @@
7c7df81
 	client->errorValue = stuff->depth;
32286e4
         return BadValue;
32286e4
     }
7c7df81
+
32286e4
 CreatePmap:
32286e4
-    VERIFY_SHMSIZE(shmdesc, stuff->offset,
32286e4
-		   PixmapBytePad(stuff->width, stuff->depth) * stuff->height,
32286e4
-		   client);
7c7df81
+    /* now w/h/d are valid; but will they overflow a 32-bit pointer? */
7c7df81
+    size = PixmapBytePad(width, depth) * height;
7c7df81
+    if (sizeof(void *) == 4 && BitsPerPixel(depth) > 8) {
7c7df81
+        if (size < width * height)
7c7df81
+            return BadAlloc;
7c7df81
+        /* thankfully, offset is unsigned */
7c7df81
+        if (stuff->offset + size < size)
7c7df81
+            return BadAlloc;
7c7df81
+    }
7c7df81
+
32286e4
+    VERIFY_SHMSIZE(shmdesc, stuff->offset, size, client);
32286e4
 
32286e4
     if(!(newPix = (PanoramiXRes *) xalloc(sizeof(PanoramiXRes))))
32286e4
 	return BadAlloc;
7c7df81
@@ -1049,6 +1067,8 @@
32286e4
     register int i;
32286e4
     ShmDescPtr shmdesc;
32286e4
     REQUEST(xShmCreatePixmapReq);
32286e4
+    unsigned int width, height, depth;
32286e4
+    unsigned long size;
32286e4
 
32286e4
     REQUEST_SIZE_MATCH(xShmCreatePixmapReq);
32286e4
     client->errorValue = stuff->pid;
7c7df81
@@ -1057,11 +1077,18 @@
32286e4
     LEGAL_NEW_RESOURCE(stuff->pid, client);
32286e4
     VERIFY_GEOMETRABLE(pDraw, stuff->drawable, client);
32286e4
     VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client);
32286e4
-    if (!stuff->width || !stuff->height)
32286e4
+    
32286e4
+    width = stuff->width;
32286e4
+    height = stuff->height;
32286e4
+    depth = stuff->depth;
32286e4
+    if (!width || !height || !depth)
32286e4
     {
32286e4
 	client->errorValue = 0;
32286e4
         return BadValue;
32286e4
     }
32286e4
+    if (width > 32767 || height > 32767)
32286e4
+	return BadAlloc;
32286e4
+
32286e4
     if (stuff->depth != 1)
32286e4
     {
32286e4
         pDepth = pDraw->pScreen->allowedDepths;
7c7df81
@@ -1071,10 +1098,19 @@
7c7df81
 	client->errorValue = stuff->depth;
32286e4
         return BadValue;
32286e4
     }
7c7df81
+
32286e4
 CreatePmap:
32286e4
-    VERIFY_SHMSIZE(shmdesc, stuff->offset,
32286e4
-		   PixmapBytePad(stuff->width, stuff->depth) * stuff->height,
32286e4
-		   client);
7c7df81
+    /* now w/h/d are valid; but will they overflow a 32-bit pointer? */
7c7df81
+    size = PixmapBytePad(width, depth) * height;
7c7df81
+    if (sizeof(void *) == 4 && BitsPerPixel(depth) > 8) {
7c7df81
+        if (size < width * height)
7c7df81
+            return BadAlloc;
7c7df81
+        /* thankfully, offset is unsigned */
7c7df81
+        if (stuff->offset + size < size)
7c7df81
+            return BadAlloc;
7c7df81
+    }
7c7df81
+
32286e4
+    VERIFY_SHMSIZE(shmdesc, stuff->offset, size, client);
32286e4
     pMap = (*shmFuncs[pDraw->pScreen->myNum]->CreatePixmap)(
32286e4
 			    pDraw->pScreen, stuff->width,
32286e4
 			    stuff->height, stuff->depth,