summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2013-03-10 00:22:14 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2013-05-23 08:13:26 -0700
commitef82512288d8ca36ac0beeb289f158195b0a8cae (patch)
treee479ca0ef85dada4c1a2b69902ea68c769ed1fbc /src
parent17071c1c608247800b2ca03a35b1fcc9c4cabe6c (diff)
Avoid integer overflow in XListInputDevices() [CVE-2013-1984 8/8]
If the length of the reply as reported by the Xserver is too long, it could overflow the calculation for the size of the buffer to copy the reply into, causing memory corruption. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'src')
-rw-r--r--src/XListDev.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/XListDev.c b/src/XListDev.c
index 1fa4747..1c14b96 100644
--- a/src/XListDev.c
+++ b/src/XListDev.c
@@ -60,6 +60,7 @@ SOFTWARE.
#include <X11/extensions/XInput.h>
#include <X11/extensions/extutil.h>
#include "XIint.h"
+#include <limits.h>
/* Calculate length field to a multiples of sizeof(XID). XIDs are typedefs
* to ulong and thus may be 8 bytes on some platforms. This can trigger a
@@ -179,7 +180,7 @@ XListInputDevices(
XAnyClassPtr Any;
char *nptr, *Nptr;
int i;
- long rlen;
+ unsigned long rlen;
XExtDisplayInfo *info = XInput_find_display(dpy);
LockDisplay(dpy);
@@ -198,9 +199,10 @@ XListInputDevices(
if ((*ndevices = rep.ndevices)) { /* at least 1 input device */
size = *ndevices * sizeof(XDeviceInfo);
- rlen = rep.length << 2; /* multiply length by 4 */
- list = (xDeviceInfo *) Xmalloc(rlen);
- slist = list;
+ if (rep.length < (INT_MAX >> 2)) {
+ rlen = rep.length << 2; /* multiply length by 4 */
+ slist = list = Xmalloc(rlen);
+ }
if (!slist) {
_XEatDataWords(dpy, rep.length);
UnlockDisplay(dpy);