[PATCH] IOMUX: Fix access past end of console_devices
andy.shevchenko at gmail.com
Wed Mar 30 19:01:38 CEST 2022
On Wed, Mar 30, 2022 at 7:49 PM Sean Anderson <seanga2 at gmail.com> wrote:
> We should only access console_devices[file][i] once we have checked that
> i < cd_count[file]. Otherwise, we will access uninitialized memory at the end of
> the loop. console_devices[file][i] should not be NULL, but putting the
> assignment in the loop condition allows us to ensure that i is checked
> beforehand. This isn't a bug, but it does make valgrind stop complaining.
> Fixes: 400797cad3 ("IOMUX: Split out for_each_console_dev() helper macro")
Has this been tested? See below.
> #define for_each_console_dev(i, file, dev) \
> - for (i = 0, dev = console_devices[file][i]; \
When we enter the loop, the dev is assigned and perhaps valid
> - i < cd_count[file]; \
> - i++, dev = console_devices[file][i])
> + for (i = 0; i < cd_count[file] && \
Not the case anymore.
> + (dev = console_devices[file][i]); i++)
With Best Regards,
More information about the U-Boot