]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[initrd] Allow for zero-length initrd files
authorMichael Brown <mcb30@ipxe.org>
Thu, 18 Feb 2021 01:49:23 +0000 (01:49 +0000)
committerMichael Brown <mcb30@ipxe.org>
Thu, 18 Feb 2021 01:49:23 +0000 (01:49 +0000)
A zero-length initrd file will currently cause an endless loop during
reshuffling as the empty image is repeatedly swapped with itself.

Fix by terminating the inner loop before considering an image as a
candidate to be swapped with itself.

Reported-by: Pico Mitchell <pico@randomapplications.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/x86/image/initrd.c

index 8f6366d3df20f0f114249d8dc0ef9d65cba61c46..49b959a91b42f0251f01b3df6135b541f3876d8a 100644 (file)
@@ -175,18 +175,18 @@ static int initrd_swap_any ( userptr_t free, size_t free_len ) {
                /* Search for adjacent image */
                for_each_image ( high ) {
 
-                       /* If we have found the adjacent image, swap and exit */
-                       if ( high->data == adjacent ) {
-                               initrd_swap ( low, high, free, free_len );
-                               return 1;
-                       }
-
                        /* Stop search if all remaining potential
                         * adjacent images are already in the correct
                         * order.
                         */
                        if ( high == low )
                                break;
+
+                       /* If we have found the adjacent image, swap and exit */
+                       if ( high->data == adjacent ) {
+                               initrd_swap ( low, high, free, free_len );
+                               return 1;
+                       }
                }
        }