[PATCH 1/1] boot: boot_flow_iter_set() called with uninitialized methods_flag

Some code paths do not initialize methods_flag before using it. Initialize it to 0 in the definition line.
Addresses-Coverity-ID: ("467057 Uninitialized scalar variable") Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- boot/bootflow.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/boot/bootflow.c b/boot/bootflow.c index 05484fd5b1..4b32d74fe1 100644 --- a/boot/bootflow.c +++ b/boot/bootflow.c @@ -241,7 +241,7 @@ static int iter_incr(struct bootflow_iter *iter) if (iter->flags & BOOTFLOWIF_SINGLE_DEV) { ret = -ENOENT; } else { - int method_flags; + int method_flags = 0;
ret = 0; dev = iter->dev; @@ -260,7 +260,6 @@ static int iter_incr(struct bootflow_iter *iter) } else if (IS_ENABLED(CONFIG_BOOTSTD_FULL) && iter->flags & BOOTFLOWIF_SINGLE_MEDIA) { log_debug("next in single\n"); - method_flags = 0; do { /* * Move to the next bootdev child of this media @@ -302,7 +301,6 @@ static int iter_incr(struct bootflow_iter *iter) } } else { ret = bootdev_next_prio(iter, &dev); - method_flags = 0; } } log_debug("ret=%d, dev=%p %s\n", ret, dev,

On Sun, Jan 07, 2024 at 09:56:07AM +0100, Heinrich Schuchardt wrote:
Some code paths do not initialize methods_flag before using it. Initialize it to 0 in the definition line.
Addresses-Coverity-ID: ("467057 Uninitialized scalar variable") Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
boot/bootflow.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/boot/bootflow.c b/boot/bootflow.c index 05484fd5b1..4b32d74fe1 100644 --- a/boot/bootflow.c +++ b/boot/bootflow.c @@ -241,7 +241,7 @@ static int iter_incr(struct bootflow_iter *iter) if (iter->flags & BOOTFLOWIF_SINGLE_DEV) { ret = -ENOENT; } else {
int method_flags;
int method_flags = 0;
ret = 0; dev = iter->dev;
@@ -260,7 +260,6 @@ static int iter_incr(struct bootflow_iter *iter) } else if (IS_ENABLED(CONFIG_BOOTSTD_FULL) && iter->flags & BOOTFLOWIF_SINGLE_MEDIA) { log_debug("next in single\n");
method_flags = 0; do { /* * Move to the next bootdev child of this media
@@ -302,7 +301,6 @@ static int iter_incr(struct bootflow_iter *iter) } } else { ret = bootdev_next_prio(iter, &dev);
} log_debug("ret=%d, dev=%p %s\n", ret, dev,method_flags = 0; }
So this leads to test failure: ========================================== FAILURES =========================================== ___________________________ test_ut[ut_bootstd_bootdev_test_order] ____________________________ test/py/tests/test_ut.py:510: in test_ut assert output.endswith('Failures: 0') E AssertionError: assert False E + where False = <built-in method endswith of str object at 0x563a7dff6e80>('Failures: 0') E + where <built-in method endswith of str object at 0x563a7dff6e80> = 'Test: bootdev_test_order: bootdev.c\r\r\nstarting USB...\r\r\nBus usb@1: scanning bus usb@1 for devices... 5 USB Devi...rder(): 5 == iter.num_devs: Expected 0x5 (5), got 0x4 (4)\r\r\nTest bootdev_test_order failed 2 times\r\r\nFailures: 2'.endswith ------------------------------------ Captured stdout call ------------------------------------- => ut bootstd bootdev_test_order Test: bootdev_test_order: bootdev.c starting USB... Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found scanning usb for storage devices... 27 Storage Device(s) found test/boot/bootdev.c:228, bootdev_test_order(): 5 == iter.num_devs: Expected 0x5 (5), got 0x4 (4) Test: bootdev_test_order: bootdev.c (flat tree) starting USB... Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found scanning usb for storage devices... 30 Storage Device(s) found test/boot/bootdev.c:228, bootdev_test_order(): 5 == iter.num_devs: Expected 0x5 (5), got 0x4 (4) Test bootdev_test_order failed 2 times Failures: 2 => =================================== short test summary info =================================== FAILED test/py/tests/test_ut.py::test_ut[ut_bootstd_bootdev_test_order] - AssertionError: as... !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ================== 1 failed, 123 passed, 89 skipped, 21 deselected in 25.70s ==================
Which is in turn test/boot/bootdev.c::bootdev_test_order() and looking at that code, I don't really understand why we expect 5 to be the expected value, nor why it becomes 4 now.
participants (2)
-
Heinrich Schuchardt
-
Tom Rini