Commit 9501bce2 authored by Alan Coopersmith's avatar Alan Coopersmith Committed by Ulrich Sibiller

integer overflow in XGetImage() [CVE-2013-1981 11/13]

Ensure that we don't underallocate when the server claims to have sent a very large reply. Signed-off-by: 's avatarAlan Coopersmith <alan.coopersmith@oracle.com> Reviewed-by: 's avatarMatthieu Herrb <matthieu.herrb@laas.fr> Signed-off-by: 's avatarJulien Cristau <jcristau@debian.org> Backported-to-NX-by: 's avatarUlrich Sibiller <uli42@gmx.de>
parent 361d3677
......@@ -30,6 +30,7 @@ in this Software without prior written authorization from The Open Group.
#include "Xlibint.h"
#include <nx-X11/Xutil.h> /* for XDestroyImage */
#include "ImUtil.h"
#include <limits.h>
#define ROUNDUP(nbytes, pad) (((((nbytes) - 1) + (pad)) / (pad)) * (pad))
......@@ -56,7 +57,7 @@ XImage *XGetImage (
xGetImageReply rep;
register xGetImageReq *req;
char *data;
long nbytes;
unsigned long nbytes;
XImage *image;
LockDisplay(dpy);
GetReq (GetImage, req);
......@@ -78,10 +79,13 @@ XImage *XGetImage (
return (XImage *)NULL;
}
nbytes = (long)rep.length << 2;
data = (char *) Xmalloc((unsigned) nbytes);
if (rep.length < (INT_MAX >> 2)) {
nbytes = (unsigned long)rep.length << 2;
data = Xmalloc(nbytes);
} else
data = NULL;
if (! data) {
_XEatData(dpy, (unsigned long) nbytes);
_XEatDataWords(dpy, rep.length);
UnlockDisplay(dpy);
SyncHandle();
return (XImage *) NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment