bus: stm32_firewall: fix off by one in stm32_firewall_get_firewall()
authorDan Carpenter <dan.carpenter@linaro.org>
Fri, 12 Apr 2024 08:25:37 +0000 (11:25 +0300)
committerAlexandre Torgue <alexandre.torgue@foss.st.com>
Thu, 25 Apr 2024 12:44:39 +0000 (14:44 +0200)
The "nb_firewall" variable is the number of elements in the firewall[]
array, which is allocated in stm32_firewall_populate_bus().  So change
this > comparison to >= to prevent an out of bound access.

Fixes: 5c9668cfc6d7 ("firewall: introduce stm32_firewall framework")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Gatien Chevallier <gatien.chevallier@foss.st.com>
Signed-off-by: Alexandre Torgue <alexandre.torgue@foss.st.com>
drivers/bus/stm32_firewall.c

index decb7944904767455d913fc8c4e5ea7348ea9b7b..2fc9761dadecf3a4099e4b1d9ce7c76699450382 100644 (file)
@@ -53,7 +53,7 @@ int stm32_firewall_get_firewall(struct device_node *np, struct stm32_firewall *f
                        return err;
                }
 
-               if (j > nb_firewall) {
+               if (j >= nb_firewall) {
                        pr_err("Too many firewall controllers");
                        of_node_put(provider);
                        return -EINVAL;