:: commit d49c98056c17639ce412d43ad15cd8a7570d8bdd

Mintsuki <mintsuki@protonmail.com> — 2026-01-12 21:24

parents: 5fa474fc0f

host/limine: Fix buffer overflow in GPT-to-MBR conversion

diff --git a/host/limine.c b/host/limine.c
index 559caeeb..107716b9 100644
--- a/host/limine.c
+++ b/host/limine.c
@@ -818,6 +818,13 @@ static int bios_install(int argc, char *argv[]) {
                 continue;
             }
 
+            if (part_to_conv_i == 4) {
+                if (!quiet) {
+                    fprintf(stderr, "GPT contains more than 4 partitions, will not convert.\n");
+                }
+                goto no_mbr_conv;
+            }
+
             if (ENDSWAP(gpt_entry.starting_lba) > UINT32_MAX) {
                 if (!quiet) {
                     fprintf(stderr, "Starting LBA of partition %" PRIi64 " is greater than UINT32_MAX, will not convert GPT.\n", i + 1);
@@ -852,13 +859,6 @@ static int bios_install(int argc, char *argv[]) {
                 goto no_mbr_conv;
             }
 
-            if (part_to_conv_i == 4) {
-                if (!quiet) {
-                    fprintf(stderr, "GPT contains more than 4 partitions, will not convert.\n");
-                }
-                goto no_mbr_conv;
-            }
-
             part_to_conv[part_to_conv_i].type = type;
 
             part_to_conv_i++;
tab: 248 wrap: offon