From: Karl Tomlinson Date: Wed, 24 Oct 2012 01:05:25 +0000 Subject: MakeBigReq: don't move the last word, already handled by Data32 The case where req->length = 1 was already not functional. Reported by Abhishek Arya . https://bugzilla.mozilla.org/show_bug.cgi?id=803762 Reviewed-by: Jeff Muizelaar --- libX11-1.5.0/include/X11/Xlibint.h 2012-10-24 12:36:48.768190632 +1300 +++ libX11-1.5.0/include/X11/Xlibint.h 2012-10-26 10:49:05.498523215 +1300 @@ -498,51 +498,66 @@ extern void *_XGetRequest(Display *dpy, #define GetEmptyReq(name, req) \ req = (xReq *) _XGetRequest(dpy, X_##name, SIZEOF(xReq)) #else #define GetEmptyReq(name, req) \ req = (xReq *) _XGetRequest(dpy, X_/**/name, SIZEOF(xReq)) #endif +/* + * MakeBigReq sets the CARD16 "req->length" to 0 and inserts a new CARD32 + * length, after req->length, before the data in the request. The new length + * includes the "n" extra 32-bit words. + * + * Do not use MakeBigReq if there is no data already in the request. + * req->length must already be >= 2. + */ #ifdef WORD64 #define MakeBigReq(req,n) \ { \ char _BRdat[4]; \ unsigned long _BRlen = req->length - 1; \ req->length = 0; \ memcpy(_BRdat, ((char *)req) + (_BRlen << 2), 4); \ - memmove(((char *)req) + 8, ((char *)req) + 4, _BRlen << 2); \ + memmove(((char *)req) + 8, ((char *)req) + 4, (_BRlen - 1) << 2); \ memcpy(((char *)req) + 4, _BRdat, 4); \ Data32(dpy, (long *)&_BRdat, 4); \ } #else #ifdef LONG64 #define MakeBigReq(req,n) \ { \ CARD64 _BRdat; \ CARD32 _BRlen = req->length - 1; \ req->length = 0; \ _BRdat = ((CARD32 *)req)[_BRlen]; \ - memmove(((char *)req) + 8, ((char *)req) + 4, _BRlen << 2); \ + memmove(((char *)req) + 8, ((char *)req) + 4, (_BRlen - 1) << 2); \ ((CARD32 *)req)[1] = _BRlen + n + 2; \ Data32(dpy, &_BRdat, 4); \ } #else #define MakeBigReq(req,n) \ { \ CARD32 _BRdat; \ CARD32 _BRlen = req->length - 1; \ req->length = 0; \ _BRdat = ((CARD32 *)req)[_BRlen]; \ - memmove(((char *)req) + 8, ((char *)req) + 4, _BRlen << 2); \ + memmove(((char *)req) + 8, ((char *)req) + 4, (_BRlen - 1) << 2); \ ((CARD32 *)req)[1] = _BRlen + n + 2; \ Data32(dpy, &_BRdat, 4); \ } #endif #endif +/* + * SetReqLen increases the count of 32-bit words in the request by "n", + * or by "badlen" if "n" is too large. + * + * Do not use SetReqLen if "req" does not already have data after the + * xReq header. req->length must already be >= 2. + */ #ifndef __clang_analyzer__ #define SetReqLen(req,n,badlen) \ if ((req->length + n) > (unsigned)65535) { \ if (dpy->bigreq_size) { \ MakeBigReq(req,n) \ } else { \ n = badlen; \