diff options
author | Michael Brown <mcb30@ipxe.org> | 2021-02-18 01:49:23 +0000 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2021-02-18 01:49:23 +0000 |
commit | 8446a439b37ae0a70693899363d0ee7c24fba935 (patch) | |
tree | 0c79f12a96ae33ea7db15690b5a189240b0adeb8 | |
parent | 4039b54ba308757c4d3ef4845453637819be59d6 (diff) | |
download | ipxe-8446a439b37ae0a70693899363d0ee7c24fba935.zip ipxe-8446a439b37ae0a70693899363d0ee7c24fba935.tar.gz ipxe-8446a439b37ae0a70693899363d0ee7c24fba935.tar.bz2 |
[initrd] Allow for zero-length initrd files
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>
-rw-r--r-- | src/arch/x86/image/initrd.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/arch/x86/image/initrd.c b/src/arch/x86/image/initrd.c index 8f6366d..49b959a 100644 --- a/src/arch/x86/image/initrd.c +++ b/src/arch/x86/image/initrd.c @@ -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; + } } } |