summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2013-04-13 10:34:22 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2013-05-06 23:22:42 -0700
commit69457711050ac3a53859ef11790a7ac815cd7d94 (patch)
treef6e48a5398c46feab01b340d9b03bc394dfd8076 /src
parent83e7693515369d57dcd11c2bb1f03563f51bc500 (diff)
downloadxorg-lib-libXRes-69457711050ac3a53859ef11790a7ac815cd7d94.tar.gz
Use _XEatDataWords to avoid overflow of rep.length shifting
rep.length is a CARD32, so rep.length << 2 could overflow in 32-bit builds Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'src')
-rw-r--r--src/XRes.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/XRes.c b/src/XRes.c
index 1744196..1ab1db8 100644
--- a/src/XRes.c
+++ b/src/XRes.c
@@ -13,6 +13,18 @@
#include <X11/extensions/XResproto.h>
#include <X11/extensions/XRes.h>
#include <assert.h>
+#include <limits.h>
+
+#ifndef HAVE__XEATDATAWORDS
+static inline void _XEatDataWords(Display *dpy, unsigned long n)
+{
+# ifndef LONG64
+ if (n >= (ULONG_MAX >> 2))
+ _XIOError(dpy);
+# endif
+ _XEatData (dpy, n << 2);
+}
+#endif
static XExtensionInfo _xres_ext_info_data;
static XExtensionInfo *xres_ext_info = &_xres_ext_info_data;
@@ -131,7 +143,7 @@ Status XResQueryClients (
*num_clients = rep.num_clients;
result = 1;
} else {
- _XEatData(dpy, rep.length << 2);
+ _XEatDataWords(dpy, rep.length);
}
}
@@ -183,7 +195,7 @@ Status XResQueryClientResources (
*num_types = rep.num_types;
result = 1;
} else {
- _XEatData(dpy, rep.length << 2);
+ _XEatDataWords(dpy, rep.length);
}
}