1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
From eb0cf9b0ba0ad213954a15c757932b8005bff99e Mon Sep 17 00:00:00 2001
From: Alan Coopersmith <alan.coopersmith@oracle.com>
Date: Wed, 1 May 2013 23:58:39 -0700
Subject: [PATCH 3/3] 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>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
(cherry picked from commit 59b8e1388a687f871831ac5a9e0ac11de75e2516)
(cherry picked from commit 4579fadd11883c62db486ecc64c40342c2ab5506)
---
configure.ac | 6 ++++++
src/XGMotion.c | 2 +-
src/XGetDCtl.c | 2 +-
src/XGetDProp.c | 5 ++---
src/XGetFCtl.c | 2 +-
src/XGetKMap.c | 2 +-
src/XGetMMap.c | 2 +-
src/XGetProp.c | 4 +---
src/XGtSelect.c | 2 +-
src/XIProperties.c | 7 +++----
src/XIint.h | 19 +++++++++++++++++++
src/XListDProp.c | 2 +-
src/XListDev.c | 2 +-
src/XOpenDev.c | 2 +-
src/XQueryDv.c | 2 +-
15 files changed, 41 insertions(+), 20 deletions(-)
diff --git a/configure.ac b/configure.ac
index 9d5d5eb..3ffdef3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,6 +28,12 @@ XORG_CHECK_MALLOC_ZERO
# Obtain compiler/linker options for depedencies
PKG_CHECK_MODULES(XI, [xproto >= 7.0.13] [x11 >= 1.2.99.1] [xextproto >= 7.0.3] [xext >= 1.0.99.1] [inputproto >= 1.9.99.902])
+# Check for _XEatDataWords function that may be patched into older Xlib releases
+SAVE_LIBS="$LIBS"
+LIBS="$XI_LIBS"
+AC_CHECK_FUNCS([_XEatDataWords])
+LIBS="$SAVE_LIBS"
+
# Check for xmlto and asciidoc for man page conversion
# (only needed by people building tarballs)
if test "$have_xmlto" = yes && test "$have_asciidoc" = yes; then
diff --git a/src/XGMotion.c b/src/XGMotion.c
index aee6671..f3b6751 100644
--- a/src/XGMotion.c
+++ b/src/XGMotion.c
@@ -109,7 +109,7 @@ XGetDeviceMotionEvents(
Xfree(bufp);
Xfree(savp);
*nEvents = 0;
- _XEatData(dpy, (unsigned long)size);
+ _XEatDataWords(dpy, rep.length);
UnlockDisplay(dpy);
SyncHandle();
return (NULL);
diff --git a/src/XGetDCtl.c b/src/XGetDCtl.c
index 729b0a0..a1e49ee 100644
--- a/src/XGetDCtl.c
+++ b/src/XGetDCtl.c
@@ -91,7 +91,7 @@ XGetDeviceControl(
nbytes = (long)rep.length << 2;
d = (xDeviceState *) Xmalloc((unsigned)nbytes);
if (!d) {
- _XEatData(dpy, (unsigned long)nbytes);
+ _XEatDataWords(dpy, rep.length);
goto out;
}
sav = d;
diff --git a/src/XGetDProp.c b/src/XGetDProp.c
index 5d44f91..f9e8f0c 100644
--- a/src/XGetDProp.c
+++ b/src/XGetDProp.c
@@ -112,14 +112,13 @@ XGetDeviceProperty(Display* dpy, XDevice* dev,
* This part of the code should never be reached. If it is,
* the server sent back a property with an invalid format.
*/
- nbytes = rep.length << 2;
- _XEatData(dpy, (unsigned long) nbytes);
+ _XEatDataWords(dpy, rep.length);
UnlockDisplay(dpy);
SyncHandle();
return(BadImplementation);
}
if (! *prop) {
- _XEatData(dpy, (unsigned long) nbytes);
+ _XEatDataWords(dpy, rep.length);
UnlockDisplay(dpy);
SyncHandle();
return(BadAlloc);
diff --git a/src/XGetFCtl.c b/src/XGetFCtl.c
index 3d64404..5a05397 100644
--- a/src/XGetFCtl.c
+++ b/src/XGetFCtl.c
@@ -91,7 +91,7 @@ XGetFeedbackControl(
nbytes = (long)rep.length << 2;
f = (xFeedbackState *) Xmalloc((unsigned)nbytes);
if (!f) {
- _XEatData(dpy, (unsigned long)nbytes);
+ _XEatDataWords(dpy, rep.length);
goto out;
}
sav = f;
diff --git a/src/XGetKMap.c b/src/XGetKMap.c
index 4596ff0..0f1d077 100644
--- a/src/XGetKMap.c
+++ b/src/XGetKMap.c
@@ -95,7 +95,7 @@ XGetDeviceKeyMapping(register Display * dpy, XDevice * dev,
if (mapping)
_XRead(dpy, (char *)mapping, nbytes);
else
- _XEatData(dpy, (unsigned long)nbytes);
+ _XEatDataWords(dpy, rep.length);
}
UnlockDisplay(dpy);
diff --git a/src/XGetMMap.c b/src/XGetMMap.c
index a4bf094..a9b5950 100644
--- a/src/XGetMMap.c
+++ b/src/XGetMMap.c
@@ -89,7 +89,7 @@ XGetDeviceModifierMapping(
if (res->modifiermap)
_XReadPad(dpy, (char *)res->modifiermap, nbytes);
else
- _XEatData(dpy, (unsigned long)nbytes);
+ _XEatDataWords(dpy, rep.length);
res->max_keypermod = rep.numKeyPerModifier;
}
diff --git a/src/XGetProp.c b/src/XGetProp.c
index 7ccf9fe..ca6f657 100644
--- a/src/XGetProp.c
+++ b/src/XGetProp.c
@@ -65,7 +65,6 @@ XGetDeviceDontPropagateList(
int *count)
{
XEventClass *list = NULL;
- int rlen;
xGetDeviceDontPropagateListReq *req;
xGetDeviceDontPropagateListReply rep;
XExtDisplayInfo *info = XInput_find_display(dpy);
@@ -87,7 +86,6 @@ XGetDeviceDontPropagateList(
*count = rep.count;
if (*count) {
- rlen = rep.length << 2;
list = (XEventClass *) Xmalloc(rep.length * sizeof(XEventClass));
if (list) {
int i;
@@ -102,7 +100,7 @@ XGetDeviceDontPropagateList(
list[i] = (XEventClass) ec;
}
} else
- _XEatData(dpy, (unsigned long)rlen);
+ _XEatDataWords(dpy, rep.length);
}
UnlockDisplay(dpy);
diff --git a/src/XGtSelect.c b/src/XGtSelect.c
index dea8c4c..495e40b 100644
--- a/src/XGtSelect.c
+++ b/src/XGtSelect.c
@@ -101,7 +101,7 @@ XGetSelectedExtensionEvents(
(XEventClass *) Xmalloc(*this_client_count *
sizeof(XEventClass));
if (!*this_client_list) {
- _XEatData(dpy, (unsigned long)tlen + alen);
+ _XEatDataWords(dpy, rep.length);
UnlockDisplay(dpy);
SyncHandle();
return (Success);
diff --git a/src/XIProperties.c b/src/XIProperties.c
index 83a7a68..5e58fb6 100644
--- a/src/XIProperties.c
+++ b/src/XIProperties.c
@@ -64,7 +64,7 @@ XIListProperties(Display* dpy, int deviceid, int *num_props_return)
props = (Atom*)Xmalloc(rep.num_properties * sizeof(Atom));
if (!props)
{
- _XEatData(dpy, rep.num_properties << 2);
+ _XEatDataWords(dpy, rep.length);
goto cleanup;
}
@@ -203,8 +203,7 @@ XIGetProperty(Display* dpy, int deviceid, Atom property, long offset,
* This part of the code should never be reached. If it is,
* the server sent back a property with an invalid format.
*/
- nbytes = rep.length << 2;
- _XEatData(dpy, nbytes);
+ _XEatDataWords(dpy, rep.length);
UnlockDisplay(dpy);
SyncHandle();
return(BadImplementation);
@@ -222,7 +221,7 @@ XIGetProperty(Display* dpy, int deviceid, Atom property, long offset,
*data = Xmalloc(rbytes);
if (!(*data)) {
- _XEatData(dpy, nbytes);
+ _XEatDataWords(dpy, rep.length);
UnlockDisplay(dpy);
SyncHandle();
return(BadAlloc);
diff --git a/src/XIint.h b/src/XIint.h
index b27f04a..5de4913 100644
--- a/src/XIint.h
+++ b/src/XIint.h
@@ -5,7 +5,12 @@
#ifndef _XIINT_H_
#define _XIINT_H_
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include <X11/extensions/XI.h>
+#include <config.h>
extern XExtDisplayInfo *XInput_find_display(Display *);
@@ -65,4 +70,18 @@ next_block(void **ptr, int size) {
return ret;
}
+#ifndef HAVE__XEATDATAWORDS
+#include <X11/Xmd.h> /* for LONG64 on 64-bit platforms */
+#include <limits.h>
+
+static inline void _XEatDataWords(Display *dpy, unsigned long n)
+{
+# ifndef LONG64
+ if (n >= (ULONG_MAX >> 2))
+ _XIOError(dpy);
+# endif
+ _XEatData (dpy, n << 2);
+}
+#endif
+
#endif
diff --git a/src/XListDProp.c b/src/XListDProp.c
index 66b9eca..a87164d 100644
--- a/src/XListDProp.c
+++ b/src/XListDProp.c
@@ -65,7 +65,7 @@ XListDeviceProperties(Display* dpy, XDevice* dev, int *nprops_return)
props = (Atom*)Xmalloc(rep.nAtoms * sizeof(Atom));
if (!props)
{
- _XEatData(dpy, rep.nAtoms << 2);
+ _XEatDataWords(dpy, rep.length);
goto cleanup;
}
diff --git a/src/XListDev.c b/src/XListDev.c
index c544ae0..ad8f548 100644
--- a/src/XListDev.c
+++ b/src/XListDev.c
@@ -187,7 +187,7 @@ XListInputDevices(
list = (xDeviceInfo *) Xmalloc(rlen);
slist = list;
if (!slist) {
- _XEatData(dpy, (unsigned long)rlen);
+ _XEatDataWords(dpy, rep.length);
UnlockDisplay(dpy);
SyncHandle();
return (XDeviceInfo *) NULL;
diff --git a/src/XOpenDev.c b/src/XOpenDev.c
index b50d5b0..e09ccbd 100644
--- a/src/XOpenDev.c
+++ b/src/XOpenDev.c
@@ -98,7 +98,7 @@ XOpenDevice(
if (rlen - dlen > 0)
_XEatData(dpy, (unsigned long)rlen - dlen);
} else
- _XEatData(dpy, (unsigned long)rlen);
+ _XEatDataWords(dpy, rep.length);
UnlockDisplay(dpy);
SyncHandle();
diff --git a/src/XQueryDv.c b/src/XQueryDv.c
index 637d5cf..9ef0190 100644
--- a/src/XQueryDv.c
+++ b/src/XQueryDv.c
@@ -88,7 +88,7 @@ XQueryDeviceState(
if (rlen > 0) {
data = Xmalloc(rlen);
if (!data) {
- _XEatData(dpy, (unsigned long)rlen);
+ _XEatDataWords(dpy, rep.length);
goto out;
}
_XRead(dpy, data, rlen);
--
1.7.7.1
|