From 3b542ca7119c13c9c860716df62b5c6e3720b49a Mon Sep 17 00:00:00 2001 From: jief666 Date: Fri, 26 Mar 2021 00:15:15 +0300 Subject: [PATCH] Fix crash when sub menu has no entries. --- rEFIt_UEFI/entry_scan/loader.cpp | 157 ++++++++++------------- rEFIt_UEFI/gui/REFIT_MAINMENU_SCREEN.cpp | 4 +- 2 files changed, 72 insertions(+), 89 deletions(-) diff --git a/rEFIt_UEFI/entry_scan/loader.cpp b/rEFIt_UEFI/entry_scan/loader.cpp index 650640153..0c0a68547 100644 --- a/rEFIt_UEFI/entry_scan/loader.cpp +++ b/rEFIt_UEFI/entry_scan/loader.cpp @@ -846,34 +846,26 @@ void LOADER_ENTRY::AddDefaultMenu() if (OSFLAG_ISSET(Flags, OSFLAG_HIBERNATED)) { SubEntry = getPartiallyDuplicatedEntry(); - if (SubEntry) { - SubEntry->Title.takeValueFrom("Cancel hibernate wake"); - SubEntry->Flags = OSFLAG_UNSET(SubEntry->Flags, OSFLAG_HIBERNATED); - SubScreen->AddMenuEntry(SubEntry, true); - } + SubEntry->Title.takeValueFrom("Cancel hibernate wake"); + SubEntry->Flags = OSFLAG_UNSET(SubEntry->Flags, OSFLAG_HIBERNATED); + SubScreen->AddMenuEntry(SubEntry, true); } SubEntry = getPartiallyDuplicatedEntry(); - if (SubEntry) { - SubEntry->Title.SWPrintf("Boot %s with selected options", macOS); - SubScreen->AddMenuEntry(SubEntry, true); - } + SubEntry->Title.SWPrintf("Boot %s with selected options", macOS); + SubScreen->AddMenuEntry(SubEntry, true); #if 0 SubEntry = getPartiallyDuplicatedEntry(); - if (SubEntry) { - SubEntry->Title.SWPrintf("Boot %s with injected kexts", macOS); - SubEntry->Flags = OSFLAG_UNSET(SubEntry->Flags, OSFLAG_CHECKFAKESMC); - SubEntry->Flags = OSFLAG_SET(SubEntry->Flags, OSFLAG_WITHKEXTS); - SubScreen->AddMenuEntry(SubEntry, true); - } + SubEntry->Title.SWPrintf("Boot %s with injected kexts", macOS); + SubEntry->Flags = OSFLAG_UNSET(SubEntry->Flags, OSFLAG_CHECKFAKESMC); + SubEntry->Flags = OSFLAG_SET(SubEntry->Flags, OSFLAG_WITHKEXTS); + SubScreen->AddMenuEntry(SubEntry, true); SubEntry = getPartiallyDuplicatedEntry(); - if (SubEntry) { - SubEntry->Title.SWPrintf("Boot %s without injected kexts", macOS); - SubEntry->Flags = OSFLAG_UNSET(SubEntry->Flags, OSFLAG_CHECKFAKESMC); - SubEntry->Flags = OSFLAG_UNSET(SubEntry->Flags, OSFLAG_WITHKEXTS); - SubScreen->AddMenuEntry(SubEntry, true); - } + SubEntry->Title.SWPrintf("Boot %s without injected kexts", macOS); + SubEntry->Flags = OSFLAG_UNSET(SubEntry->Flags, OSFLAG_CHECKFAKESMC); + SubEntry->Flags = OSFLAG_UNSET(SubEntry->Flags, OSFLAG_WITHKEXTS); + SubScreen->AddMenuEntry(SubEntry, true); #endif SubScreen->AddMenuEntry(SubMenuKextInjectMgmt(), true); SubScreen->AddMenuInfo_f("=== boot-args ==="); @@ -916,58 +908,50 @@ void LOADER_ENTRY::AddDefaultMenu() // default entry SubEntry = getPartiallyDuplicatedEntry(); - if (SubEntry) { - SubEntry->Title.SWPrintf("Run %ls", FileName.wc_str()); - SubScreen->AddMenuEntry(SubEntry, true); - } + SubEntry->Title.SWPrintf("Run %ls", FileName.wc_str()); + SubScreen->AddMenuEntry(SubEntry, true); SubEntry = getPartiallyDuplicatedEntry(); - if (SubEntry) { + if (Quiet) { + SubEntry->Title.SWPrintf("%ls verbose", Title.s()); + SubEntry->LoadOptions.removeIC(quietLitteral); + } else { + SubEntry->Title.SWPrintf("%ls quiet", Title.s()); + SubEntry->LoadOptions.AddID(quietLitteral); + } + SubScreen->AddMenuEntry(SubEntry, true); + + SubEntry = getPartiallyDuplicatedEntry(); + if (WithSplash) { + SubEntry->Title.SWPrintf("%ls without splash", Title.s()); + SubEntry->LoadOptions.removeIC(splashLitteral); + } else { + SubEntry->Title.SWPrintf("%ls with splash", Title.s()); + SubEntry->LoadOptions.AddID(splashLitteral); + } + SubScreen->AddMenuEntry(SubEntry, true); + + SubEntry = getPartiallyDuplicatedEntry(); + if (WithSplash) { if (Quiet) { - SubEntry->Title.SWPrintf("%ls verbose", Title.s()); + SubEntry->Title.SWPrintf("%ls verbose without splash", Title.s()); + SubEntry->LoadOptions.removeIC(splashLitteral); SubEntry->LoadOptions.removeIC(quietLitteral); } else { - SubEntry->Title.SWPrintf("%ls quiet", Title.s()); - SubEntry->LoadOptions.AddID(quietLitteral); - } - SubScreen->AddMenuEntry(SubEntry, true); - } - - SubEntry = getPartiallyDuplicatedEntry(); - if (SubEntry) { - if (WithSplash) { - SubEntry->Title.SWPrintf("%ls without splash", Title.s()); + SubEntry->Title.SWPrintf("%ls quiet without splash",Title.s()); SubEntry->LoadOptions.removeIC(splashLitteral); - } else { - SubEntry->Title.SWPrintf("%ls with splash", Title.s()); - SubEntry->LoadOptions.AddID(splashLitteral); + SubEntry->LoadOptions.Add(quietLitteral); } - SubScreen->AddMenuEntry(SubEntry, true); - } - - SubEntry = getPartiallyDuplicatedEntry(); - if (SubEntry) { - if (WithSplash) { - if (Quiet) { - SubEntry->Title.SWPrintf("%ls verbose without splash", Title.s()); - SubEntry->LoadOptions.removeIC(splashLitteral); - SubEntry->LoadOptions.removeIC(quietLitteral); - } else { - SubEntry->Title.SWPrintf("%ls quiet without splash",Title.s()); - SubEntry->LoadOptions.removeIC(splashLitteral); - SubEntry->LoadOptions.Add(quietLitteral); - } - } else if (Quiet) { - SubEntry->Title.SWPrintf("%ls verbose with splash",Title.s()); - SubEntry->LoadOptions.removeIC(quietLitteral); // - SubEntry->LoadOptions.AddID(splashLitteral); - } else { - SubEntry->Title.SWPrintf("%ls quiet with splash",Title.s()); - SubEntry->LoadOptions.AddID(quietLitteral); - SubEntry->LoadOptions.AddID(splashLitteral); - } - SubScreen->AddMenuEntry(SubEntry, true); + } else if (Quiet) { + SubEntry->Title.SWPrintf("%ls verbose with splash",Title.s()); + SubEntry->LoadOptions.removeIC(quietLitteral); // + SubEntry->LoadOptions.AddID(splashLitteral); + } else { + SubEntry->Title.SWPrintf("%ls quiet with splash",Title.s()); + SubEntry->LoadOptions.AddID(quietLitteral); + SubEntry->LoadOptions.AddID(splashLitteral); } + SubScreen->AddMenuEntry(SubEntry, true); } else if ((LoaderType == OSTYPE_WIN) || (LoaderType == OSTYPE_WINEFI)) { // by default, skip the built-in selection and boot from hard disk only @@ -977,36 +961,33 @@ void LOADER_ENTRY::AddDefaultMenu() // default entry SubEntry = getPartiallyDuplicatedEntry(); - if (SubEntry) { - SubEntry->Title.SWPrintf("Run %ls", FileName.wc_str()); - SubScreen->AddMenuEntry(SubEntry, true); - } + SubEntry->Title.SWPrintf("Run %ls", FileName.wc_str()); + SubScreen->AddMenuEntry(SubEntry, true); SubEntry = getPartiallyDuplicatedEntry(); - if (SubEntry) { - SubEntry->Title.takeValueFrom("Boot Windows from Hard Disk"); - SubScreen->AddMenuEntry(SubEntry, true); - } + SubEntry->Title.takeValueFrom("Boot Windows from Hard Disk"); + SubScreen->AddMenuEntry(SubEntry, true); SubEntry = getPartiallyDuplicatedEntry(); - if (SubEntry) { - SubEntry->Title.takeValueFrom("Boot Windows from CD-ROM"); - LoadOptions.setEmpty(); - LoadOptions.Add("-s"_XS8); - LoadOptions.Add("-c"_XS8); - SubScreen->AddMenuEntry(SubEntry, true); - } + SubEntry->Title.takeValueFrom("Boot Windows from CD-ROM"); + LoadOptions.setEmpty(); + LoadOptions.Add("-s"_XS8); + LoadOptions.Add("-c"_XS8); + SubScreen->AddMenuEntry(SubEntry, true); SubEntry = getPartiallyDuplicatedEntry(); - if (SubEntry) { - SubEntry->Title.SWPrintf("Run %ls in text mode", FileName.wc_str()); - SubEntry->Flags = OSFLAG_UNSET(SubEntry->Flags, OSFLAG_USEGRAPHICS); - LoadOptions.setEmpty(); - LoadOptions.Add("-v"_XS8); - SubEntry->LoaderType = OSTYPE_OTHER; // Sothor - Why are we using OSTYPE_OTHER here? - SubScreen->AddMenuEntry(SubEntry, true); - } + SubEntry->Title.SWPrintf("Run %ls in text mode", FileName.wc_str()); + SubEntry->Flags = OSFLAG_UNSET(SubEntry->Flags, OSFLAG_USEGRAPHICS); + LoadOptions.setEmpty(); + LoadOptions.Add("-v"_XS8); + SubEntry->LoaderType = OSTYPE_OTHER; // Sothor - Why are we using OSTYPE_OTHER here? + SubScreen->AddMenuEntry(SubEntry, true); + }else{ + // default entry + SubEntry = getPartiallyDuplicatedEntry(); + SubEntry->Title.SWPrintf("Run %ls", FileName.wc_str()); + SubScreen->AddMenuEntry(SubEntry, true); } // SubScreen->AddMenuEntry(&MenuEntryReturn, false); //one-way ticket to avoid confusion diff --git a/rEFIt_UEFI/gui/REFIT_MAINMENU_SCREEN.cpp b/rEFIt_UEFI/gui/REFIT_MAINMENU_SCREEN.cpp index b0b6840a6..f5d2c011b 100644 --- a/rEFIt_UEFI/gui/REFIT_MAINMENU_SCREEN.cpp +++ b/rEFIt_UEFI/gui/REFIT_MAINMENU_SCREEN.cpp @@ -752,7 +752,7 @@ UINTN REFIT_MAINMENU_SCREEN::RunMainMenu(IN INTN DefaultSelection, OUT REFIT_ABS MenuExit = RunGenericMenu(&DefaultEntryIndex, &MainChosenEntry); TimeoutSeconds = 0; - if (MenuExit == MENU_EXIT_DETAILS && MainChosenEntry->SubScreen != NULL) { + if (MenuExit == MENU_EXIT_DETAILS && MainChosenEntry->SubScreen != NULL && MainChosenEntry->SubScreen->Entries.size() > 0) { // if MainChosenEntry->SubScreen->Entries.size() == 0, we got a crash in GraphicsMenuStyle XString8Array TmpArgs; if ( gSettings.Boot.BootArgs.length() > 0) { TmpArgs = Split(gSettings.Boot.BootArgs, " "); @@ -865,6 +865,8 @@ UINTN REFIT_MAINMENU_SCREEN::RunMainMenu(IN INTN DefaultSelection, OUT REFIT_ABS } //--------- } + }else{ + MenuExit = 0; // loop on main menu } }