Skip to content

Commit

Permalink
Immediately boot into original bootloader on missing md5sum.txt
Browse files Browse the repository at this point in the history
* And also silence the related error.
  • Loading branch information
pbatard committed Feb 27, 2024
1 parent cd4c261 commit cf00bb3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
24 changes: 15 additions & 9 deletions src/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,17 @@ STATIC EFI_STATUS ExitProcess(
// If we have a bootloader to chain load, try to launch it
if (DevicePath != NULL) {
if (EFI_ERROR(Status) && Status != EFI_ABORTED && !IsTestMode) {
// Ask the user if they want to continue
SetText(TEXT_YELLOW);
PrintCentered(L"Continue with boot? [y/N]", Console.Rows - 2);
gST->ConIn->Reset(gST->ConIn, FALSE);
while (gST->ConIn->ReadKeyStroke(gST->ConIn, &Key) == EFI_NOT_READY);
if (Key.UnicodeChar != L'y' && Key.UnicodeChar != L'Y') {
SafeFree(DevicePath);
return Status;
// Ask the user if they want to continue, unless md5sum.txt could
// not be found, in which case continue boot right away.
if (Status != EFI_NOT_FOUND) {
SetText(TEXT_YELLOW);
PrintCentered(L"Continue with boot? [y/N]", Console.Rows - 2);
gST->ConIn->Reset(gST->ConIn, FALSE);
while (gST->ConIn->ReadKeyStroke(gST->ConIn, &Key) == EFI_NOT_READY);
if (Key.UnicodeChar != L'y' && Key.UnicodeChar != L'Y') {
SafeFree(DevicePath);
return Status;
}
}
RunCountDown = FALSE;
}
Expand Down Expand Up @@ -266,7 +269,10 @@ EFI_STATUS EFIAPI efi_main(
if (SetPathCase(Root, LoaderPath) == EFI_SUCCESS)
DevicePath = FileDevicePath(DeviceHandle, LoaderPath);

// Parse md5sum.txt to construct a hash list
// Parse md5sum.txt to construct a hash list.
// We parse the full file, rather than process it line by line so that we
// can report progress and, unless md5sum_totalbytes is always specified at
// the beginning, progress requires knowing how many files we have to hash.
Status = Parse(Root, HASH_FILE, &HashList);
if (EFI_ERROR(Status))
goto out;
Expand Down
1 change: 1 addition & 0 deletions src/boot.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ BOOLEAN IsTestSystem(VOID);
@retval EFI_SUCCESS The file was successfully parsed and the hash list is populated.
@retval EFI_INVALID_PARAMETER One or more of the input parameters are invalid.
@retval EFI_OUT_OF_RESOURCES A memory allocation error occurred.
@retval EFI_NOT_FOUND The hash list file does not exist.
@retval EFI_UNSUPPORTED The hash list file is too small or too large.
@retval EFI_END_OF_FILE The hash list file could not be read.
@retval EFI_ABORTED The hash list file contains invalid data.
Expand Down
6 changes: 5 additions & 1 deletion src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ STATIC CONST CHAR8 TotalBytesString[] = "md5sum_totalbytes";
@retval EFI_SUCCESS The file was successfully parsed and the hash list is populated.
@retval EFI_INVALID_PARAMETER One or more of the input parameters are invalid.
@retval EFI_OUT_OF_RESOURCES A memory allocation error occurred.
@retval EFI_NOT_FOUND The hash list file does not exist.
@retval EFI_UNSUPPORTED The hash list file is too small or too large.
@retval EFI_END_OF_FILE The hash list file could not be read.
@retval EFI_ABORTED The hash list file contains invalid data.
Expand All @@ -55,7 +56,10 @@ EFI_STATUS Parse(
// Look for the hash file on the boot partition
Status = Root->Open(Root, &File, (CHAR16*)Path, EFI_FILE_MODE_READ, EFI_FILE_READ_ONLY);
if (EFI_ERROR(Status)) {
PrintError(L"Unable to locate '%s'", Path);
// A missing md5sum.txt is not really an error, so don't
// report it, unless we're running in test mode.
if (Status != EFI_NOT_FOUND || IsTestMode)
PrintError(L"Unable to open '%s'", Path);
goto out;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/test_list.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# No Hash list
# Missing Hash list
> rm -f image/md5sum.txt
[FAIL] Unable to locate 'md5sum.txt': [14] Not Found
[FAIL] Unable to open 'md5sum.txt': [14] Not Found

# Empty Hash list
> rm -f image/md5sum.txt
Expand Down

0 comments on commit cf00bb3

Please sign in to comment.