Imported Upstream version 1.7.2
[platform/upstream/libXi.git] / src / XGetProp.c
index c5d088b..8c69ef2 100644 (file)
@@ -60,6 +60,7 @@ SOFTWARE.
 #include <X11/extensions/XInput.h>
 #include <X11/extensions/extutil.h>
 #include "XIint.h"
+#include <limits.h>
 
 XEventClass *
 XGetDeviceDontPropagateList(
@@ -68,7 +69,6 @@ XGetDeviceDontPropagateList(
     int                        *count)
 {
     XEventClass *list = NULL;
-    int rlen;
     xGetDeviceDontPropagateListReq *req;
     xGetDeviceDontPropagateListReply rep;
     XExtDisplayInfo *info = XInput_find_display(dpy);
@@ -89,11 +89,11 @@ XGetDeviceDontPropagateList(
     }
     *count = rep.count;
 
-    if (*count) {
-       rlen = rep.length << 2;
-       list = (XEventClass *) Xmalloc(rep.length * sizeof(XEventClass));
+    if (rep.length != 0) {
+       if ((rep.count != 0) && (rep.length < (INT_MAX / sizeof(XEventClass))))
+           list = Xmalloc(rep.length * sizeof(XEventClass));
        if (list) {
-           int i;
+           unsigned int i;
            CARD32 ec;
 
            /* read and assign each XEventClass separately because
@@ -104,8 +104,10 @@ XGetDeviceDontPropagateList(
                _XRead(dpy, (char *)(&ec), sizeof(CARD32));
                list[i] = (XEventClass) ec;
            }
-       } else
-           _XEatData(dpy, (unsigned long)rlen);
+       } else {
+            *count = 0;
+           _XEatDataWords(dpy, rep.length);
+        }
     }
 
     UnlockDisplay(dpy);