Boot the RAUC bootflow after setting BOOT_ORDER to a 33-character slot
name, one more than fits the "BOOT_<slot>_LEFT" env-var name buffer. The
boot must now fail with -ENAMETOOLONG.

Before the previous commit the name overflowed the stack buffer; as no
such variable exists the boot then failed with -ENOENT, hiding the
overflow.

Also check the accepted side of the boundary: a 32-character name, the
longest that fits, must pass the length check and fail only with -ENOENT
because its BOOT_<slot>_LEFT variable does not exist.

Signed-off-by: Aristo Chen <[email protected]>
---
 test/boot/bootflow.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index ef4638ec700..ef8090f3f4a 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -1445,6 +1445,29 @@ static int bootflow_rauc(struct unit_test_state *uts)
 
        ut_assert_console_end();
 
+       /*
+        * Boot with a BOOT_ORDER slot name (33 chars) that is too long for the
+        * "BOOT_<slot>_LEFT" env-var name buffer. It must be rejected rather
+        * than overflow the stack.
+        */
+       ut_assertok(run_command("bootflow select 0", 0));
+       ut_assert_console_end();
+       ut_assertok(env_set("BOOT_ORDER", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 
B"));
+       ut_asserteq(1, run_command("bootflow boot", 0));
+       ut_assert_nextline("** Booting bootflow 'mmc10.bootdev.whole' with 
rauc");
+       ut_assert_nextline("Boot failed (err=%d)", -ENAMETOOLONG);
+       ut_assert_console_end();
+
+       /*
+        * A 32-char slot name is the longest that fits. It must pass the
+        * length check and fail only because BOOT_<slot>_LEFT does not exist.
+        */
+       ut_assertok(env_set("BOOT_ORDER", "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"));
+       ut_asserteq(1, run_command("bootflow boot", 0));
+       ut_assert_nextline("** Booting bootflow 'mmc10.bootdev.whole' with 
rauc");
+       ut_assert_nextline("Boot failed (err=%d)", -ENOENT);
+       ut_assert_console_end();
+
        /*
         * Scan with a BOOT_ORDER naming a slot that has no configured
         * partitions. get_slot() must not crash on the NULL array terminator;
-- 
2.43.0

Reply via email to