summaryrefslogtreecommitdiff
path: root/lib/libXi/src
diff options
context:
space:
mode:
authorDavid Coppa <dcoppa@cvs.openbsd.org>2012-01-19 08:41:07 +0000
committerDavid Coppa <dcoppa@cvs.openbsd.org>2012-01-19 08:41:07 +0000
commit98125d2304c46978a1964189d1989495ab25aa3e (patch)
tree4b2a8313369892eed9a96e5379f227f792f990ef /lib/libXi/src
parent17585c2f25b1ff350f692d3691e4ab73fa375e75 (diff)
Force class alignment to a multiple of sizeof(XID): fixes a SIGBUS
crash on sparc64. Upstream git commit 07ced7b48219e3bc0c98806f3d7106f86d1b2ca0 OK matthieu@
Diffstat (limited to 'lib/libXi/src')
-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;