1 diff --git a/Xext/EVI.c b/Xext/EVI.c
2 index 8fe3481..13bd32a 100644
5 @@ -34,6 +34,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
6 #include <X11/extensions/XEVIstr.h>
9 +#include "scrnintstr.h"
12 static unsigned char XEVIReqCode = 0;
13 @@ -87,10 +88,22 @@ ProcEVIGetVisualInfo(ClientPtr client)
15 REQUEST(xEVIGetVisualInfoReq);
16 xEVIGetVisualInfoReply rep;
17 - int n, n_conflict, n_info, sz_info, sz_conflict;
18 + int i, n, n_conflict, n_info, sz_info, sz_conflict;
20 + unsigned int total_visuals = 0;
21 xExtendedVisualInfo *eviInfo;
25 + * do this first, otherwise REQUEST_FIXED_SIZE can overflow. we assume
26 + * here that you don't have more than 2^32 visuals over all your screens;
27 + * this seems like a safe assumption.
29 + for (i = 0; i < screenInfo.numScreens; i++)
30 + total_visuals += screenInfo.screens[i]->numVisuals;
31 + if (stuff->n_visual > total_visuals)
34 REQUEST_FIXED_SIZE(xEVIGetVisualInfoReq, stuff->n_visual * sz_VisualID32);
35 status = eviPriv->getVisualInfo((VisualID32 *)&stuff[1], (int)stuff->n_visual,
36 &eviInfo, &n_info, &conflict, &n_conflict);
37 diff --git a/Xext/cup.c b/Xext/cup.c
38 index 6bfa278..781b9ce 100644
41 @@ -196,6 +196,9 @@ int ProcGetReservedColormapEntries(
43 REQUEST_SIZE_MATCH (xXcupGetReservedColormapEntriesReq);
45 + if (stuff->screen >= screenInfo.numScreens)
48 #ifndef HAVE_SPECIAL_DESKTOP_COLORS
49 citems[CUP_BLACK_PIXEL].pixel =
50 screenInfo.screens[stuff->screen]->blackPixel;
51 diff --git a/Xext/sampleEVI.c b/Xext/sampleEVI.c
52 index 7508aa7..b871bfd 100644
53 --- a/Xext/sampleEVI.c
54 +++ b/Xext/sampleEVI.c
55 @@ -34,6 +34,13 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
56 #include <X11/extensions/XEVIstr.h>
57 #include "EVIstruct.h"
58 #include "scrnintstr.h"
62 +#elif !defined(UINT32_MAX)
63 +#define UINT32_MAX 0xffffffffU
66 static int sampleGetVisualInfo(
69 @@ -42,24 +49,36 @@ static int sampleGetVisualInfo(
70 VisualID32 **conflict_rn,
73 - int max_sz_evi = n_visual * sz_xExtendedVisualInfo * screenInfo.numScreens;
74 + unsigned int max_sz_evi;
75 VisualID32 *temp_conflict;
76 xExtendedVisualInfo *evi;
77 - int max_visuals = 0, max_sz_conflict, sz_conflict = 0;
78 + unsigned int max_visuals = 0, max_sz_conflict, sz_conflict = 0;
79 register int visualI, scrI, sz_evi = 0, conflictI, n_conflict;
80 - *evi_rn = evi = (xExtendedVisualInfo *)xalloc(max_sz_evi);
84 + if (n_visual > UINT32_MAX/(sz_xExtendedVisualInfo * screenInfo.numScreens))
86 + max_sz_evi = n_visual * sz_xExtendedVisualInfo * screenInfo.numScreens;
88 for (scrI = 0; scrI < screenInfo.numScreens; scrI++) {
89 if (screenInfo.screens[scrI]->numVisuals > max_visuals)
90 max_visuals = screenInfo.screens[scrI]->numVisuals;
93 + if (n_visual > UINT32_MAX/(sz_VisualID32 * screenInfo.numScreens
96 max_sz_conflict = n_visual * sz_VisualID32 * screenInfo.numScreens * max_visuals;
98 + *evi_rn = evi = (xExtendedVisualInfo *)xalloc(max_sz_evi);
102 temp_conflict = (VisualID32 *)xalloc(max_sz_conflict);
103 if (!temp_conflict) {
108 for (scrI = 0; scrI < screenInfo.numScreens; scrI++) {
109 for (visualI = 0; visualI < n_visual; visualI++) {
110 evi[sz_evi].core_visual_id = visual[visualI];
111 diff --git a/Xext/security.c b/Xext/security.c
112 index ba057de..e9d48c9 100644
113 --- a/Xext/security.c
114 +++ b/Xext/security.c
115 @@ -1563,7 +1563,7 @@ SecurityLoadPropertyAccessList(void)
116 if (!SecurityPolicyFile)
119 - f = fopen(SecurityPolicyFile, "r");
120 + f = Fopen(SecurityPolicyFile, "r");
123 ErrorF("error opening security policy file %s\n",
124 @@ -1646,7 +1646,7 @@ SecurityLoadPropertyAccessList(void)
126 #endif /* PROPDEBUG */
130 } /* SecurityLoadPropertyAccessList */
133 diff --git a/Xext/shm.c b/Xext/shm.c
134 index ac587be..6f99e90 100644
137 @@ -711,6 +711,8 @@ ProcPanoramiXShmCreatePixmap(
138 int i, j, result, rc;
140 REQUEST(xShmCreatePixmapReq);
141 + unsigned int width, height, depth;
142 + unsigned long size;
143 PanoramiXRes *newPix;
145 REQUEST_SIZE_MATCH(xShmCreatePixmapReq);
146 @@ -724,11 +726,18 @@ ProcPanoramiXShmCreatePixmap(
149 VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client);
150 - if (!stuff->width || !stuff->height)
152 + width = stuff->width;
153 + height = stuff->height;
154 + depth = stuff->depth;
155 + if (!width || !height || !depth)
157 client->errorValue = 0;
160 + if (width > 32767 || height > 32767)
163 if (stuff->depth != 1)
165 pDepth = pDraw->pScreen->allowedDepths;
166 @@ -738,10 +747,18 @@ ProcPanoramiXShmCreatePixmap(
167 client->errorValue = stuff->depth;
172 - VERIFY_SHMSIZE(shmdesc, stuff->offset,
173 - PixmapBytePad(stuff->width, stuff->depth) * stuff->height,
175 + size = PixmapBytePad(width, depth) * height;
176 + if (sizeof(size) == 4 && BitsPerPixel(depth) > 8) {
177 + if (size < width * height)
179 + /* thankfully, offset is unsigned */
180 + if (stuff->offset + size < size)
184 + VERIFY_SHMSIZE(shmdesc, stuff->offset, size, client);
186 if(!(newPix = (PanoramiXRes *) xalloc(sizeof(PanoramiXRes))))
188 @@ -1040,6 +1057,8 @@ ProcShmCreatePixmap(client)
191 REQUEST(xShmCreatePixmapReq);
192 + unsigned int width, height, depth;
193 + unsigned long size;
195 REQUEST_SIZE_MATCH(xShmCreatePixmapReq);
196 client->errorValue = stuff->pid;
197 @@ -1052,11 +1071,18 @@ ProcShmCreatePixmap(client)
200 VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client);
201 - if (!stuff->width || !stuff->height)
203 + width = stuff->width;
204 + height = stuff->height;
205 + depth = stuff->depth;
206 + if (!width || !height || !depth)
208 client->errorValue = 0;
211 + if (width > 32767 || height > 32767)
214 if (stuff->depth != 1)
216 pDepth = pDraw->pScreen->allowedDepths;
217 @@ -1066,10 +1092,18 @@ ProcShmCreatePixmap(client)
218 client->errorValue = stuff->depth;
223 - VERIFY_SHMSIZE(shmdesc, stuff->offset,
224 - PixmapBytePad(stuff->width, stuff->depth) * stuff->height,
226 + size = PixmapBytePad(width, depth) * height;
227 + if (sizeof(size) == 4 && BitsPerPixel(depth) > 8) {
228 + if (size < width * height)
230 + /* thankfully, offset is unsigned */
231 + if (stuff->offset + size < size)
235 + VERIFY_SHMSIZE(shmdesc, stuff->offset, size, client);
236 pMap = (*shmFuncs[pDraw->pScreen->myNum]->CreatePixmap)(
237 pDraw->pScreen, stuff->width,
238 stuff->height, stuff->depth,
239 diff --git a/Xi/chgfctl.c b/Xi/chgfctl.c
240 index 2e0e13c..235d659 100644
243 @@ -327,18 +327,13 @@ ChangeStringFeedback(ClientPtr client, DeviceIntPtr dev,
244 xStringFeedbackCtl * f)
249 KeySym *syms, *sup_syms;
251 syms = (KeySym *) (f + 1);
252 if (client->swapped) {
253 swaps(&f->length, n); /* swapped num_keysyms in calling proc */
254 - p = (long *)(syms);
255 - for (i = 0; i < f->num_keysyms; i++) {
259 + SwapLongs((CARD32 *) syms, f->num_keysyms);
262 if (f->num_keysyms > s->ctrl.max_symbols) {
263 diff --git a/Xi/chgkmap.c b/Xi/chgkmap.c
264 index eac520f..75ee9f5 100644
267 @@ -79,18 +79,14 @@ int
268 SProcXChangeDeviceKeyMapping(ClientPtr client)
273 + unsigned int count;
275 REQUEST(xChangeDeviceKeyMappingReq);
276 swaps(&stuff->length, n);
277 REQUEST_AT_LEAST_SIZE(xChangeDeviceKeyMappingReq);
278 - p = (long *)&stuff[1];
279 count = stuff->keyCodes * stuff->keySymsPerKeyCode;
280 - for (i = 0; i < count; i++) {
284 + REQUEST_FIXED_SIZE(xChangeDeviceKeyMappingReq, count * sizeof(CARD32));
285 + SwapLongs((CARD32 *) (&stuff[1]), count);
286 return (ProcXChangeDeviceKeyMapping(client));
289 @@ -106,10 +102,14 @@ ProcXChangeDeviceKeyMapping(ClientPtr client)
293 + unsigned int count;
295 REQUEST(xChangeDeviceKeyMappingReq);
296 REQUEST_AT_LEAST_SIZE(xChangeDeviceKeyMappingReq);
298 + count = stuff->keyCodes * stuff->keySymsPerKeyCode;
299 + REQUEST_FIXED_SIZE(xChangeDeviceKeyMappingReq, count * sizeof(CARD32));
301 dev = LookupDeviceIntRec(stuff->deviceid);
303 SendErrorToClient(client, IReqCode, X_ChangeDeviceKeyMapping, 0,
304 diff --git a/Xi/chgprop.c b/Xi/chgprop.c
305 index 59a93c6..21bda5b 100644
308 @@ -81,19 +81,15 @@ int
309 SProcXChangeDeviceDontPropagateList(ClientPtr client)
315 REQUEST(xChangeDeviceDontPropagateListReq);
316 swaps(&stuff->length, n);
317 REQUEST_AT_LEAST_SIZE(xChangeDeviceDontPropagateListReq);
318 swapl(&stuff->window, n);
319 swaps(&stuff->count, n);
320 - p = (long *)&stuff[1];
321 - for (i = 0; i < stuff->count; i++) {
325 + REQUEST_FIXED_SIZE(xChangeDeviceDontPropagateListReq,
326 + stuff->count * sizeof(CARD32));
327 + SwapLongs((CARD32 *) (&stuff[1]), stuff->count);
328 return (ProcXChangeDeviceDontPropagateList(client));
331 diff --git a/Xi/grabdev.c b/Xi/grabdev.c
332 index e2809ef..d0b4ae7 100644
335 @@ -82,8 +82,6 @@ int
336 SProcXGrabDevice(ClientPtr client)
342 REQUEST(xGrabDeviceReq);
343 swaps(&stuff->length, n);
344 @@ -91,11 +89,11 @@ SProcXGrabDevice(ClientPtr client)
345 swapl(&stuff->grabWindow, n);
346 swapl(&stuff->time, n);
347 swaps(&stuff->event_count, n);
348 - p = (long *)&stuff[1];
349 - for (i = 0; i < stuff->event_count; i++) {
354 + if (stuff->length != (sizeof(xGrabDeviceReq) >> 2) + stuff->event_count)
357 + SwapLongs((CARD32 *) (&stuff[1]), stuff->event_count);
359 return (ProcXGrabDevice(client));
361 diff --git a/Xi/grabdevb.c b/Xi/grabdevb.c
362 index df62d0c..18db1f7 100644
365 @@ -80,8 +80,6 @@ int
366 SProcXGrabDeviceButton(ClientPtr client)
372 REQUEST(xGrabDeviceButtonReq);
373 swaps(&stuff->length, n);
374 @@ -89,11 +87,9 @@ SProcXGrabDeviceButton(ClientPtr client)
375 swapl(&stuff->grabWindow, n);
376 swaps(&stuff->modifiers, n);
377 swaps(&stuff->event_count, n);
378 - p = (long *)&stuff[1];
379 - for (i = 0; i < stuff->event_count; i++) {
383 + REQUEST_FIXED_SIZE(xGrabDeviceButtonReq,
384 + stuff->event_count * sizeof(CARD32));
385 + SwapLongs((CARD32 *) (&stuff[1]), stuff->event_count);
387 return (ProcXGrabDeviceButton(client));
389 diff --git a/Xi/grabdevk.c b/Xi/grabdevk.c
390 index b74592f..429b2f7 100644
393 @@ -80,8 +80,6 @@ int
394 SProcXGrabDeviceKey(ClientPtr client)
400 REQUEST(xGrabDeviceKeyReq);
401 swaps(&stuff->length, n);
402 @@ -89,11 +87,8 @@ SProcXGrabDeviceKey(ClientPtr client)
403 swapl(&stuff->grabWindow, n);
404 swaps(&stuff->modifiers, n);
405 swaps(&stuff->event_count, n);
406 - p = (long *)&stuff[1];
407 - for (i = 0; i < stuff->event_count; i++) {
411 + REQUEST_FIXED_SIZE(xGrabDeviceKeyReq, stuff->event_count * sizeof(CARD32));
412 + SwapLongs((CARD32 *) (&stuff[1]), stuff->event_count);
413 return (ProcXGrabDeviceKey(client));
416 diff --git a/Xi/selectev.c b/Xi/selectev.c
417 index d52db1b..19415c5 100644
420 @@ -131,19 +131,16 @@ int
421 SProcXSelectExtensionEvent(ClientPtr client)
427 REQUEST(xSelectExtensionEventReq);
428 swaps(&stuff->length, n);
429 REQUEST_AT_LEAST_SIZE(xSelectExtensionEventReq);
430 swapl(&stuff->window, n);
431 swaps(&stuff->count, n);
432 - p = (long *)&stuff[1];
433 - for (i = 0; i < stuff->count; i++) {
437 + REQUEST_FIXED_SIZE(xSelectExtensionEventReq,
438 + stuff->count * sizeof(CARD32));
439 + SwapLongs((CARD32 *) (&stuff[1]), stuff->count);
441 return (ProcXSelectExtensionEvent(client));
444 diff --git a/Xi/sendexev.c b/Xi/sendexev.c
445 index eac9abe..9803cf3 100644
448 @@ -83,7 +83,7 @@ int
449 SProcXSendExtensionEvent(ClientPtr client)
457 @@ -94,6 +94,11 @@ SProcXSendExtensionEvent(ClientPtr client)
458 REQUEST_AT_LEAST_SIZE(xSendExtensionEventReq);
459 swapl(&stuff->destination, n);
460 swaps(&stuff->count, n);
462 + if (stuff->length != (sizeof(xSendExtensionEventReq) >> 2) + stuff->count +
463 + (stuff->num_events * (sizeof(xEvent) >> 2)))
466 eventP = (xEvent *) & stuff[1];
467 for (i = 0; i < stuff->num_events; i++, eventP++) {
468 proc = EventSwapVector[eventP->u.u.type & 0177];
469 @@ -103,11 +108,8 @@ SProcXSendExtensionEvent(ClientPtr client)
473 - p = (long *)(((xEvent *) & stuff[1]) + stuff->num_events);
474 - for (i = 0; i < stuff->count; i++) {
478 + p = (CARD32 *)(((xEvent *) & stuff[1]) + stuff->num_events);
479 + SwapLongs(p, stuff->count);
480 return (ProcXSendExtensionEvent(client));
483 diff --git a/dix/dixfonts.c b/dix/dixfonts.c
484 index c21b3ec..7bb2404 100644
487 @@ -325,6 +325,13 @@ doOpenFont(ClientPtr client, OFclosurePtr c)
491 + /* check values for firstCol, lastCol, firstRow, and lastRow */
492 + if (pfont->info.firstCol > pfont->info.lastCol ||
493 + pfont->info.firstRow > pfont->info.lastRow ||
494 + pfont->info.lastCol - pfont->info.firstCol > 255) {
501 diff --git a/hw/xfree86/common/xf86MiscExt.c b/hw/xfree86/common/xf86MiscExt.c
502 index 655304e..ccb4f75 100644
503 --- a/hw/xfree86/common/xf86MiscExt.c
504 +++ b/hw/xfree86/common/xf86MiscExt.c
505 @@ -568,6 +568,10 @@ MiscExtPassMessage(int scrnIndex, const char *msgtype, const char *msgval,
507 DEBUG_P("MiscExtPassMessage");
509 + /* should check this in the protocol, but xf86NumScreens isn't exported */
510 + if (scrnIndex >= xf86NumScreens)
513 if (*pScr->HandleMessage == NULL)
514 return BadImplementation;
515 return (*pScr->HandleMessage)(scrnIndex, msgtype, msgval, retstr);