summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libXi/src/XListDev.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/lib/libXi/src/XListDev.c b/lib/libXi/src/XListDev.c
index c544ae09a..5d9e2b306 100644
--- a/lib/libXi/src/XListDev.c
+++ b/lib/libXi/src/XListDev.c
@@ -58,6 +58,17 @@ SOFTWARE.
#include <X11/extensions/extutil.h>
#include "XIint.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
+ * SIGBUS if a class ends up not being 8-aligned (e.g. after XAxisInfo).
+ */
+static int pad_to_xid(int base_size)
+{
+ int padsize = sizeof(XID);
+
+ return ((base_size + padsize - 1)/padsize) * padsize;
+}
+
static int
SizeClassInfo(xAnyClassPtr *any, int num_classes)
{
@@ -66,18 +77,18 @@ SizeClassInfo(xAnyClassPtr *any, int num_classes)
for (j = 0; j < num_classes; j++) {
switch ((*any)->class) {
case KeyClass:
- size += sizeof(XKeyInfo);
+ size += pad_to_xid(sizeof(XKeyInfo));
break;
case ButtonClass:
- size += sizeof(XButtonInfo);
+ size += pad_to_xid(sizeof(XButtonInfo));
break;
case ValuatorClass:
{
xValuatorInfoPtr v;
v = (xValuatorInfoPtr) *any;
- size += sizeof(XValuatorInfo) +
- (v->num_axes * sizeof(XAxisInfo));
+ size += pad_to_xid(sizeof(XValuatorInfo) +
+ (v->num_axes * sizeof(XAxisInfo)));
break;
}
default:
@@ -102,7 +113,7 @@ ParseClassInfo(xAnyClassPtr *any, XAnyClassPtr *Any, int num_classes)
xKeyInfoPtr k = (xKeyInfoPtr) *any;
K->class = KeyClass;
- K->length = sizeof(XKeyInfo);
+ K->length = pad_to_xid(sizeof(XKeyInfo));
K->min_keycode = k->min_keycode;
K->max_keycode = k->max_keycode;
K->num_keys = k->num_keys;
@@ -114,7 +125,7 @@ ParseClassInfo(xAnyClassPtr *any, XAnyClassPtr *Any, int num_classes)
xButtonInfoPtr b = (xButtonInfoPtr) *any;
B->class = ButtonClass;
- B->length = sizeof(XButtonInfo);
+ B->length = pad_to_xid(sizeof(XButtonInfo));
B->num_buttons = b->num_buttons;
break;
}
@@ -126,8 +137,8 @@ ParseClassInfo(xAnyClassPtr *any, XAnyClassPtr *Any, int num_classes)
xAxisInfoPtr a;
V->class = ValuatorClass;
- V->length = sizeof(XValuatorInfo) +
- (v->num_axes * sizeof(XAxisInfo));
+ V->length = pad_to_xid(sizeof(XValuatorInfo) +
+ (v->num_axes * sizeof(XAxisInfo)));
V->num_axes = v->num_axes;
V->motion_buffer = v->motion_buffer_size;
V->mode = v->mode;