[PATCH 01/27] Test: Input: Only ever set up to MAX_VALUATORS valuators

Daniel Stone daniel at fooishbar.org
Fri Jun 3 07:59:37 PDT 2011


Previously, the input tests were working up to sizeof(mask) * 8, which
could be more than the arrays; the latter only being sized as
MAX_VALUATORS.

Hypothetically, if you were switching the stored valuator values to
double instead of uint32_t, and you attempted to set the 39th member of
a MAX_VALUATORS-sized (36) array, you'd probably end up smashing
ev->key_repeat into oblivion and then tripping the check for invalid
flags because you haven't yet put XIPointerEmulated into the valid flags
for XI_Motion.  Probably.

Signed-off-by: Daniel Stone <daniel at fooishbar.org>
---
 test/xi2/protocol-eventconvert.c |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/test/xi2/protocol-eventconvert.c b/test/xi2/protocol-eventconvert.c
index edba974..6e61d74 100644
--- a/test/xi2/protocol-eventconvert.c
+++ b/test/xi2/protocol-eventconvert.c
@@ -70,6 +70,8 @@ static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
 
     for (i = 0; out->valuators_len && i < sizeof(in->valuators.mask) * 8; i++)
     {
+        if (i >= MAX_VALUATORS)
+            assert (!XIMaskIsSet(in->valuators.mask, i));
         assert (XIMaskIsSet(in->valuators.mask, i) == XIMaskIsSet(ptr, i));
         if (XIMaskIsSet(in->valuators.mask, i))
             bits_set++;
@@ -238,7 +240,7 @@ static void test_convert_XIRawEvent(void)
     test_XIRawEvent(&in);
 
     printf("Testing valuator masks\n");
-    for (i = 0; i < sizeof(in.valuators.mask) * 8; i++)
+    for (i = 0; i < MAX_VALUATORS; i++)
     {
         XISetMask(in.valuators.mask, i);
         test_XIRawEvent(&in);
@@ -257,7 +259,7 @@ static void test_convert_XIRawEvent(void)
         XIClearMask(in.valuators.mask, i);
     }
 
-    for (i = 0; i < sizeof(in.valuators.mask) * 8; i++)
+    for (i = 0; i < MAX_VALUATORS; i++)
     {
         XISetMask(in.valuators.mask, i);
         test_XIRawEvent(&in);
@@ -354,7 +356,7 @@ static void test_values_XIDeviceEvent(DeviceEvent *in, xXIDeviceEvent *out,
 
 
     valuators = 0;
-    for (i = 0; i < sizeof(in->valuators.mask) * 8; i++)
+    for (i = 0; i < MAX_VALUATORS; i++)
         if (XIMaskIsSet(in->valuators.mask, i))
             valuators++;
 
@@ -365,7 +367,9 @@ static void test_values_XIDeviceEvent(DeviceEvent *in, xXIDeviceEvent *out,
     for (i = 0; i < sizeof(in->valuators.mask) * 8 ||
                 i < (out->valuators_len * 4) * 8; i++)
     {
-        if (i > sizeof(in->valuators.mask) * 8)
+        if (i >= MAX_VALUATORS)
+            assert(!XIMaskIsSet(in->valuators.mask, i) && !XIMaskIsSet(ptr, i));
+        else if (i > sizeof(in->valuators.mask) * 8)
             assert(!XIMaskIsSet(ptr, i));
         else if (i > out->valuators_len * 4 * 8)
             assert(!XIMaskIsSet(in->valuators.mask, i));
@@ -610,14 +614,14 @@ static void test_convert_XIDeviceEvent(void)
     }
 
     printf("Testing valuator masks\n");
-    for (i = 0; i < sizeof(in.valuators.mask) * 8; i++)
+    for (i = 0; i < MAX_VALUATORS; i++)
     {
         XISetMask(in.valuators.mask, i);
         test_XIDeviceEvent(&in);
         XIClearMask(in.valuators.mask, i);
     }
 
-    for (i = 0; i < sizeof(in.valuators.mask) * 8; i++)
+    for (i = 0; i < MAX_VALUATORS; i++)
     {
         XISetMask(in.valuators.mask, i);
 
@@ -627,7 +631,7 @@ static void test_convert_XIDeviceEvent(void)
         XIClearMask(in.valuators.mask, i);
     }
 
-    for (i = 0; i < sizeof(in.valuators.mask) * 8; i++)
+    for (i = 0; i < MAX_VALUATORS; i++)
     {
         XISetMask(in.valuators.mask, i);
         test_XIDeviceEvent(&in);
-- 
1.7.5.3



More information about the xorg-devel mailing list