summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2013-03-02 15:08:21 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2013-05-09 18:59:53 -0700
commit833f6b70bc789d33607f6dbfee9e0a4178ec4b59 (patch)
treec2e4d0c2461d78f95cd82ac980d44f03fb5e2d98
parent79d8dc08eb98842173ce239b9dd60df0e9e9ae72 (diff)
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: Alan Coopersmith <alan.coopersmith@oracle.com> Reviewed-by: Matthieu Herrb <matthieu.herrb@laas.fr>
-rw-r--r--src/GetImage.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/GetImage.c b/src/GetImage.c
index e8f1b030..c461abc0 100644
--- a/src/GetImage.c
+++ b/src/GetImage.c
@@ -30,6 +30,7 @@ in this Software without prior written authorization from The Open Group.
30#include "Xlibint.h" 30#include "Xlibint.h"
31#include <X11/Xutil.h> /* for XDestroyImage */ 31#include <X11/Xutil.h> /* for XDestroyImage */
32#include "ImUtil.h" 32#include "ImUtil.h"
33#include <limits.h>
33 34
34#define ROUNDUP(nbytes, pad) (((((nbytes) - 1) + (pad)) / (pad)) * (pad)) 35#define ROUNDUP(nbytes, pad) (((((nbytes) - 1) + (pad)) / (pad)) * (pad))
35 36
@@ -56,7 +57,7 @@ XImage *XGetImage (
56 xGetImageReply rep; 57 xGetImageReply rep;
57 register xGetImageReq *req; 58 register xGetImageReq *req;
58 char *data; 59 char *data;
59 long nbytes; 60 unsigned long nbytes;
60 XImage *image; 61 XImage *image;
61 LockDisplay(dpy); 62 LockDisplay(dpy);
62 GetReq (GetImage, req); 63 GetReq (GetImage, req);
@@ -78,10 +79,13 @@ XImage *XGetImage (
78 return (XImage *)NULL; 79 return (XImage *)NULL;
79 } 80 }
80 81
81 nbytes = (long)rep.length << 2; 82 if (rep.length < (INT_MAX >> 2)) {
82 data = (char *) Xmalloc((unsigned) nbytes); 83 nbytes = (unsigned long)rep.length << 2;
84 data = Xmalloc(nbytes);
85 } else
86 data = NULL;
83 if (! data) { 87 if (! data) {
84 _XEatData(dpy, (unsigned long) nbytes); 88 _XEatDataWords(dpy, rep.length);
85 UnlockDisplay(dpy); 89 UnlockDisplay(dpy);
86 SyncHandle(); 90 SyncHandle();
87 return (XImage *) NULL; 91 return (XImage *) NULL;