diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2013-03-09 14:40:33 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2013-04-26 17:32:26 -0700 |
commit | 082d70b19848059ba78c9d1c315114fb07e8c0ef (patch) | |
tree | 06d1af17410fcc7881843bf7bcd037701a56dbf6 | |
parent | d05f27a6f74cb419ad5a437f2e4690b17e7faee5 (diff) |
integer overflow in XcupStoreColors() [CVE-2013-1982 2/6]
If the computed number of entries is large enough that it overflows when
multiplied by the size of a xColorItem struct, or is treated as negative
when compared to the size of the stack allocated buffer, then memory
corruption can occur when more bytes are read from the X server than the
size of the buffer we allocated to hold them.
The requirement to match the number of colors specified by the caller makes
this much harder to hit than the one in XcupGetReservedColormapEntries()
Reported-by: Ilja Van Sprundel <ivansprundel@ioactive.com>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | src/Xcup.c | 25 |
1 files changed, 11 insertions, 14 deletions
@@ -219,24 +219,21 @@ XcupStoreColors( } if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - long nbytes; + unsigned long nbytes; xColorItem* rbufp; xColorItem* cs; - int nentries = rep.length / 3; - - nbytes = nentries * SIZEOF (xColorItem); + unsigned int nentries = rep.length / 3; - if (nentries != ncolors) { - _XEatDataWords(dpy, rep.length); - UnlockDisplay (dpy); - SyncHandle (); - return False; - } + if ((nentries == ncolors) && + (nentries < (INT_MAX / SIZEOF (xColorItem)))) { + nbytes = nentries * SIZEOF (xColorItem); - if (ncolors > 256) - rbufp = (xColorItem*) Xmalloc (nbytes); - else - rbufp = rbuf; + if (ncolors > 256) + rbufp = Xmalloc (nbytes); + else + rbufp = rbuf; + } else + rbufp = NULL; if (rbufp == NULL) { _XEatDataWords(dpy, rep.length); |