summaryrefslogtreecommitdiff
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-04-13 10:37:39 -0700
commit95b352b0f4a1ab1bc254e78adbc73cd65223ded4 (patch)
treec27345856454d7d8b5c1970d918d451ae9a1786a
parentd54acff47096cf52a9b8e018a26f7165e1092eb5 (diff)
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>
-rw-r--r--configure.ac6
-rw-r--r--src/XRes.c15
2 files changed, 19 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index bc4e8a6..10e47d2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -55,6 +55,12 @@ RES_VERSION=[`echo $VERSION | sed 's/^\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/'`]
# Obtain compiler/linker options for depedencies
PKG_CHECK_MODULES(XRES, x11 xext xextproto [resourceproto >= $RES_VERSION])
+# Check for _XEatDataWords function that may be patched into older Xlib release
+SAVE_LIBS="$LIBS"
+LIBS="$XRES_LIBS"
+AC_CHECK_FUNCS([_XEatDataWords])
+LIBS="$SAVE_LIBS"
+
AC_CONFIG_FILES([Makefile
src/Makefile
man/Makefile
diff --git a/src/XRes.c b/src/XRes.c
index 6091c96..ae86206 100644
--- a/src/XRes.c
+++ b/src/XRes.c
@@ -12,7 +12,18 @@
#include <X11/extensions/extutil.h>
#include <X11/extensions/XResproto.h>
#include <X11/extensions/XRes.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 +142,7 @@ Status XResQueryClients (
*num_clients = rep.num_clients;
result = 1;
} else {
- _XEatData(dpy, rep.length << 2);
+ _XEatDataWords(dpy, rep.length);
}
}
@@ -183,7 +194,7 @@ Status XResQueryClientResources (
*num_types = rep.num_types;
result = 1;
} else {
- _XEatData(dpy, rep.length << 2);
+ _XEatDataWords(dpy, rep.length);
}
}