Hi Denis,

On 2026-07-29T08:23:51, NG, BOON KHAI via U-Boot
<[email protected]> wrote:
> pytest: fix out of bounds access to bad_pattern_ids

Subject is fine, but please sharpen the body: with pattern_lab_mode at
index 1, every bad-pattern index is off by one, so the wrong id is
reported and a match on the final bad pattern indexes past the end of
bad_pattern_ids.

>
> Current logic in ConsoleBase() mislabels every bad pattern and walks
> pattern past the end when the last one matches.
>
> Ensure out of bound access to bad_pattern_ids is handled correctly
> while processing test console output.
>
> Fixes: 8308a5eed6e6 ("test: Introduce lab mode")
> Signed-off-by: Denis Mukhin <[email protected]>
>
> test/py/console_base.py | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)

> diff --git a/test/py/console_base.py b/test/py/console_base.py
> @@ -212,24 +212,24 @@ class ConsoleBase(object):
> -                    m = self.p.expect([pattern_u_boot_spl_signon,
> -                                       pattern_lab_mode] + self.bad_patterns)
> +                    extra_patterns = [pattern_u_boot_spl_signon, 
> pattern_lab_mode]
> +                    m = self.p.expect(extra_patterns + self.bad_patterns)
>                      if m == 1:
>                          self.set_lab_mode()
>                          break
>                      elif m != 0:
>                          raise BootFail('Bad pattern found on SPL console: ' +
> -                                       self.bad_pattern_ids[m - 1])
> +                                       self.bad_pattern_ids[m - 
> len(extra_patterns)])

The fix is correct. Please hoist the length into a local so the offset
arithmetic reads more clearly, e.g.:

    extra_patterns = [pattern_u_boot_spl_signon, pattern_lab_mode]
    base = len(extra_patterns)
    m = self.p.expect(extra_patterns + self.bad_patterns)
    ...
    raise BootFail('Bad pattern found on SPL console: ' +
                   self.bad_pattern_ids[m - base])

Same for the main-signon block below. What do you think?

BTW while you are here, please double-check the other
bad_pattern_ids[m - 1] sites in this file - the pattern is only
correct where exactly one non-bad pattern precedes self.bad_patterns.

Regards,
Simon

Reply via email to