test: Make udev_properties array fixed-size.
authorJohn Chadwick <johnwchadwick@gmail.com>
Fri, 27 Sep 2019 03:06:11 +0000 (20:06 -0700)
committerJohn Chadwick <johnwchadwick@gmail.com>
Fri, 27 Sep 2019 03:06:11 +0000 (20:06 -0700)
The udev_properties array is currently variable length, which causes the
tests to invoke undefined behavior on empty lists, as it attempts to
access the first array item to check if the key is NULL, which is an out
of bounds read and will fail when the struct alignment happens to line
up such that there is no padding after the list in the empty list case.

By making the udev_properties array 32 items long, it can encapsulate
every existing case, with only a fairly small amount of memory overhead,
and without requiring every single `TEST_DEVICE` call to initialize
`udev_properties`.

test/litest-int.h

index 24d608742600840561e2e0c2366768c8a57e324f..598c8d0a5015f23542aead0a31dae184ad315081 100644 (file)
@@ -77,7 +77,7 @@ struct litest_test_device {
        const char *udev_rule;
        const char *quirk_file;
 
-       const struct key_value_str udev_properties[];
+       const struct key_value_str udev_properties[32];
 };
 
 struct litest_device_interface {