vc4: Avoid overflowing various static tables.
authorEric Anholt <eric@anholt.net>
Wed, 29 Jul 2015 21:40:10 +0000 (14:40 -0700)
committerEric Anholt <eric@anholt.net>
Thu, 30 Jul 2015 22:46:27 +0000 (15:46 -0700)
src/gallium/drivers/vc4/kernel/vc4_validate.c
src/gallium/drivers/vc4/vc4_cl_dump.c
src/gallium/drivers/vc4/vc4_formats.c
src/gallium/drivers/vc4/vc4_qpu_disasm.c

index cba948a1c670e726575600727527bee6d60fcc2c..674ca63786471d34ead83ce6071075664cd851d0 100644 (file)
@@ -487,7 +487,7 @@ vc4_validate_bin_cl(struct drm_device *dev,
                u8 cmd = *(uint8_t *)src_pkt;
                const struct cmd_info *info;
 
-               if (cmd > ARRAY_SIZE(cmd_info)) {
+               if (cmd >= ARRAY_SIZE(cmd_info)) {
                        DRM_ERROR("0x%08x: packet %d out of bounds\n",
                                  src_offset, cmd);
                        return -EINVAL;
index e153a2430905513e4942165bdaa4dc6783248866..6d748010baf814177a96c53c3c7afdc17ffe4e0d 100644 (file)
@@ -397,7 +397,7 @@ vc4_dump_cl(void *cl, uint32_t size, bool is_render)
         while (offset < size) {
                 uint8_t header = cmds[offset];
 
-                if (header > ARRAY_SIZE(packet_info) ||
+                if (header >= ARRAY_SIZE(packet_info) ||
                     !packet_info[header].name) {
                         fprintf(stderr, "0x%08x 0x%08x: Unknown packet 0x%02x (%d)!\n",
                                 offset, hw_offset, header, header);
index 004bac70c67e45674dd36efa6519303db0030540..ffce61237de47e296de65a7ea35fa99a209cb453 100644 (file)
@@ -108,7 +108,7 @@ static const struct vc4_format vc4_format_table[] = {
 static const struct vc4_format *
 get_format(enum pipe_format f)
 {
-        if (f > ARRAY_SIZE(vc4_format_table) ||
+        if (f >= ARRAY_SIZE(vc4_format_table) ||
             !vc4_format_table[f].present)
                 return NULL;
         else
index 55e0e6139b53b49cc6816c80b66ba8c80e43e5ae..00aeb300a9b615f352c5e28275d8b37f6269d54d 100644 (file)
@@ -225,7 +225,7 @@ static const char *qpu_condflags[] = {
 };
 
 #define DESC(array, index)                                        \
-        ((index > ARRAY_SIZE(array) || !(array)[index]) ?         \
+        ((index >= ARRAY_SIZE(array) || !(array)[index]) ?         \
          "???" : (array)[index])
 
 static const char *