Commit 8673bf07 authored by Alan Coopersmith's avatar Alan Coopersmith Committed by Ulrich Sibiller

integer overflow in XListHosts() [CVE-2013-1981 5/13]

If the reported number of host entries is too large, the calculations to allocate memory for them may overflow, leaving us writing beyond the bounds of the allocation. Reported-by: 's avatarIlja Van Sprundel <ivansprundel@ioactive.com> 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 7d18bbe9
...@@ -62,6 +62,8 @@ X Window System is a trademark of The Open Group. ...@@ -62,6 +62,8 @@ X Window System is a trademark of The Open Group.
#include <config.h> #include <config.h>
#endif #endif
#include "Xlibint.h" #include "Xlibint.h"
#include <limits.h>
/* /*
* can be freed using XFree. * can be freed using XFree.
*/ */
...@@ -73,7 +75,6 @@ XHostAddress *XListHosts ( ...@@ -73,7 +75,6 @@ XHostAddress *XListHosts (
{ {
register XHostAddress *outbuf = NULL, *op; register XHostAddress *outbuf = NULL, *op;
xListHostsReply reply; xListHostsReply reply;
long nbytes;
unsigned char *buf, *bp; unsigned char *buf, *bp;
register unsigned i; register unsigned i;
register xListHostsReq *req; register xListHostsReq *req;
...@@ -90,19 +91,26 @@ XHostAddress *XListHosts ( ...@@ -90,19 +91,26 @@ XHostAddress *XListHosts (
} }
if (reply.nHosts) { if (reply.nHosts) {
nbytes = reply.length << 2; /* compute number of bytes in reply */ unsigned long nbytes = reply.length << 2; /* number of bytes in reply */
const unsigned long max_hosts = INT_MAX /
(sizeof(XHostAddress) + sizeof(XServerInterpretedAddress));
if (reply.nHosts < max_hosts) {
unsigned long hostbytes = reply.nHosts *
(sizeof(XHostAddress) + sizeof(XServerInterpretedAddress));
op = outbuf = (XHostAddress *) if (reply.length < (INT_MAX >> 2) &&
Xmalloc((unsigned) (nbytes + (hostbytes >> 2) < ((INT_MAX >> 2) - reply.length))
(reply.nHosts * sizeof(XHostAddress)) + outbuf = Xmalloc(nbytes + hostbytes);
(reply.nHosts * sizeof(XServerInterpretedAddress)))); }
if (! outbuf) { if (! outbuf) {
_XEatData(dpy, (unsigned long) nbytes); _XEatDataWords(dpy, reply.length);
UnlockDisplay(dpy); UnlockDisplay(dpy);
SyncHandle(); SyncHandle();
return (XHostAddress *) NULL; return (XHostAddress *) NULL;
} }
op = outbuf;
sip = (XServerInterpretedAddress *) sip = (XServerInterpretedAddress *)
(((unsigned char *) outbuf) + (reply.nHosts * sizeof(XHostAddress))); (((unsigned char *) outbuf) + (reply.nHosts * sizeof(XHostAddress)));
bp = buf = ((unsigned char *) sip) bp = buf = ((unsigned char *) sip)
......
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