summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2013-05-03 23:10:47 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2013-05-03 23:25:57 -0700
commitf34f6f64698c3b957aadba7315bb13726e3d79b0 (patch)
tree2ae9ee3a0cb4488556c59317ec3d9325e517a161
parent9f470c92bc2d194c8abb9154f42864e6c82f43ef (diff)
Use _XEatDataWords to avoid overflow of rep.length bit 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.ac7
-rw-r--r--src/dmx.c17
2 files changed, 24 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 24e03fc..4629cf8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -43,6 +43,13 @@ XORG_CHECK_MALLOC_ZERO
# Obtain compiler/linker options for depedencies
PKG_CHECK_MODULES(DMX, x11 xext xextproto [dmxproto >= 2.2.99.1])
+# Check for _XEatDataWords function that may be patched into older Xlib releases
+SAVE_LIBS="$LIBS"
+LIBS="$DMX_LIBS"
+AC_CHECK_FUNCS([_XEatDataWords])
+LIBS="$SAVE_LIBS"
+
+
AC_CONFIG_FILES([Makefile
src/Makefile
man/Makefile
diff --git a/src/dmx.c b/src/dmx.c
index 201568e..e43d624 100644
--- a/src/dmx.c
+++ b/src/dmx.c
@@ -38,12 +38,16 @@
* can be included in client applications by linking with the libdmx.a
* library. */
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
#include <X11/Xlibint.h>
#include <X11/extensions/Xext.h>
#define EXTENSION_PROC_ARGS void *
#include <X11/extensions/extutil.h>
#include <X11/extensions/dmxproto.h>
#include <X11/extensions/dmxext.h>
+#include <limits.h>
static XExtensionInfo dmx_extension_info_data;
static XExtensionInfo *dmx_extension_info = &dmx_extension_info_data;
@@ -82,6 +86,19 @@ static XEXT_GENERATE_FIND_DISPLAY(find_display, dmx_extension_info,
static XEXT_GENERATE_CLOSE_DISPLAY(close_display, dmx_extension_info)
+#ifndef HAVE__XEATDATAWORDS
+#include <X11/Xmd.h> /* for LONG64 on 64-bit platforms */
+
+static inline void _XEatDataWords(Display *dpy, unsigned long n)
+{
+# ifndef LONG64
+ if (n >= (ULONG_MAX >> 2))
+ _XIOError(dpy);
+# endif
+ _XEatData (dpy, n << 2);
+}
+#endif
+
/*****************************************************************************
* *