From: srs5694 Date: Sun, 1 Mar 2015 18:57:35 +0000 (-0500) Subject: Misc. changes, mostly to fix minor or rare bugs. X-Git-Url: https://code.delx.au/refind/commitdiff_plain/4944145c8979880d164195efcd9dae809c5bbf7e Misc. changes, mostly to fix minor or rare bugs. --- diff --git a/NEWS.txt b/NEWS.txt index 29762a7..9437e23 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -1,11 +1,27 @@ 0.8.7 (?/??/2015): ------------------ +- Added identification of XFS as filesystem type in volume descriptions. + +- More fixes to filesystem type detection code. Previous version sometimes + identified FAT or NTFS (or anything with a boot loader) as a whole-disk + device rather than the correct filesystem type. + +- Added protections to the code to reduce the risk of crashes that might + occur when dereferencing NULL pointers in various situations. + +- I'm deprecating the use of filesystem numbers (as in "fs0:") because + they're unreliable -- filesystem numbers can change between boots and + might not be the same as those used in an EFI shell or other program. + Sooner or later I'll remove code supporting this feature. In the + meantime, if it doesn't work for you, please switch to using filesystem + labels, partition labels, or partition GUIDs. + - Added detection of FreeBSD's BIOS-mode GPT boot loader. Previously, rEFInd could detect FreeBSD's BIOS-mode MBR boot loader, which gave - FreeBSD an appropriate icon on Macs; but the GPT boot loader code is - different, so some recent FreeBSD installations showed up with generic - grey diamond icons. This change creates FreeBSD icons instead. + FreeBSD an appropriate icon on Macs; but the BIOS-mode GPT boot loader + code is different, so some recent FreeBSD installations showed up with + generic grey diamond icons. This change creates FreeBSD icons instead. - Added "Secure Boot [active|inactive]" notice to "about" menu for x86 (32-bit) systems, since there are now a few 32-bit UEFI systems that diff --git a/docs/refind/configfile.html b/docs/refind/configfile.html index d38a8d4..b6e6e97 100644 --- a/docs/refind/configfile.html +++ b/docs/refind/configfile.html @@ -325,7 +325,7 @@ timeout 20 also_scan_dirs directory path(s) - Adds the specified directory or directories to the directory list that rEFInd scans for EFI boot loaders when scanfor includes the internal, external, or optical options. Directories are specified relative to the filesystem's root directory. You may precede a directory path with a volume name and colon, as in somevol:/extra/path, to restrict the extra scan to a single volume. A volume number, preceded by fs, can be used for volumes that lack names, as in fs1:/extra/path. If you don't specify a volume name or number, this option is applied to all the filesystems that rEFInd scans. If a specified directory doesn't exist, rEFInd ignores it (no error results). The default value is boot, which is useful for locating Linux kernels when you have an EFI driver for your Linux root (/) filesystem. To add to, rather than replace, the default value, specify + as the first item in the list, as in also_scan_dirs +,loaders. + Adds the specified directory or directories to the directory list that rEFInd scans for EFI boot loaders when scanfor includes the internal, external, or optical options. Directories are specified relative to the filesystem's root directory. You may precede a directory path with a volume name and colon, as in somevol:/extra/path, to restrict the extra scan to a single volume. A volume number, preceded by fs, can be used for volumes that lack names, as in fs1:/extra/path. (This usage is deprecated.) If you don't specify a volume name or number, this option is applied to all the filesystems that rEFInd scans. If a specified directory doesn't exist, rEFInd ignores it (no error results). The default value is boot, which is useful for locating Linux kernels when you have an EFI driver for your Linux root (/) filesystem. To add to, rather than replace, the default value, specify + as the first item in the list, as in also_scan_dirs +,loaders. dont_scan_volumes or don't_scan_volumes @@ -335,7 +335,7 @@ timeout 20 dont_scan_dirs or don't_scan_dirs directory path(s) - Adds the specified directory or directories to a directory "blacklist"—these directories are not scanned for boot loaders. You may optionally precede a directory path with a volume name and a colon to limit the blacklist to that volume; otherwise all volumes are affected. For instance, EFI/BOOT prevents scanning the EFI/BOOT directory on all volumes, whereas ESP:EFI/BOOT blocks scans of EFI/BOOT on the volume called ESP but not on other volumes. You can use a filesystem number, as in fs0, in place of a volume name. This token may be useful to keep duplicate boot loaders out of the menu; or to keep drivers or utilities out of the boot menu, if you've stored them in a subdirectory of EFI. This option takes precedence over also_scan_dirs; if a directory appears in both lists, it will not be scanned. To add directories to the default list rather than replace the list, specify + as the first option, as in dont_scan_dirs + EFI/dontscan. The default for this token is EFI/tools, EFI/tools/memtest86, EFI/tools/memtest, EFI/memtest86, EFI/memtest, com.apple.recovery.boot. + Adds the specified directory or directories to a directory "blacklist"—these directories are not scanned for boot loaders. You may optionally precede a directory path with a volume name and a colon to limit the blacklist to that volume; otherwise all volumes are affected. For instance, EFI/BOOT prevents scanning the EFI/BOOT directory on all volumes, whereas ESP:EFI/BOOT blocks scans of EFI/BOOT on the volume called ESP but not on other volumes. You can use a filesystem number, as in fs0, in place of a volume name. (The use of filesystem numbers is deprecated.) This token may be useful to keep duplicate boot loaders out of the menu; or to keep drivers or utilities out of the boot menu, if you've stored them in a subdirectory of EFI. This option takes precedence over also_scan_dirs; if a directory appears in both lists, it will not be scanned. To add directories to the default list rather than replace the list, specify + as the first option, as in dont_scan_dirs + EFI/dontscan. The default for this token is EFI/tools, EFI/tools/memtest86, EFI/tools/memtest, EFI/memtest86, EFI/memtest, com.apple.recovery.boot. dont_scan_files or don't_scan_files diff --git a/filesystems/fsw_efi.c b/filesystems/fsw_efi.c index 5313069..d92554b 100644 --- a/filesystems/fsw_efi.c +++ b/filesystems/fsw_efi.c @@ -67,8 +67,8 @@ EFI_GUID gEfiDriverBindingProtocolGuid = EFI_DRIVER_BINDING_PROTOCOL_GUID; EFI_GUID gEfiComponentNameProtocolGuid = EFI_COMPONENT_NAME_PROTOCOL_GUID; -extern EFI_GUID gEfiDiskIoProtocolGuid = EFI_DISK_IO_PROTOCOL_GUID; -extern EFI_GUID gEfiBlockIoProtocolGuid = EFI_BLOCK_IO_PROTOCOL_GUID; +EFI_GUID gEfiDiskIoProtocolGuid = EFI_DISK_IO_PROTOCOL_GUID; +EFI_GUID gEfiBlockIoProtocolGuid = EFI_BLOCK_IO_PROTOCOL_GUID; EFI_GUID gEfiFileInfoGuid = EFI_FILE_INFO_ID; EFI_GUID gEfiFileSystemInfoGuid = EFI_FILE_SYSTEM_INFO_ID; EFI_GUID gEfiFileSystemVolumeLabelInfoIdGuid = EFI_FILE_SYSTEM_VOLUME_LABEL_INFO_ID; diff --git a/libeg/image.c b/libeg/image.c index 0322d12..614d312 100644 --- a/libeg/image.c +++ b/libeg/image.c @@ -34,7 +34,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* - * Modifications copyright (c) 2012-2014 Roderick W. Smith + * Modifications copyright (c) 2012-2015 Roderick W. Smith * * Modifications distributed under the terms of the GNU General Public * License (GPL) version 3 (GPLv3), a copy of which must be distributed @@ -199,7 +199,7 @@ VOID egFreeImage(IN EG_IMAGE *Image) // Basic file operations // -EFI_STATUS egLoadFile(IN EFI_FILE* BaseDir, IN CHAR16 *FileName, OUT UINT8 **FileData, OUT UINTN *FileDataLength) +EFI_STATUS egLoadFile(IN EFI_FILE *BaseDir, IN CHAR16 *FileName, OUT UINT8 **FileData, OUT UINTN *FileDataLength) { EFI_STATUS Status; EFI_FILE_HANDLE FileHandle; @@ -208,6 +208,9 @@ EFI_STATUS egLoadFile(IN EFI_FILE* BaseDir, IN CHAR16 *FileName, OUT UINT8 **Fil UINTN BufferSize; UINT8 *Buffer; + if ((BaseDir == NULL) || (FileName == NULL)) + return EFI_NOT_FOUND; + Status = refit_call5_wrapper(BaseDir->Open, BaseDir, &FileHandle, FileName, EFI_FILE_MODE_READ, 0); if (EFI_ERROR(Status)) { return Status; @@ -617,27 +620,6 @@ VOID egComposeImage(IN OUT EG_IMAGE *CompImage, IN EG_IMAGE *TopImage, IN UINTN } } /* VOID egComposeImage() */ -// EG_IMAGE * egEnsureImageSize(IN EG_IMAGE *Image, IN UINTN Width, IN UINTN Height, IN EG_PIXEL *Color) -// { -// EG_IMAGE *NewImage; -// -// if (Image == NULL) -// return NULL; -// if (Image->Width == Width && Image->Height == Height) -// return Image; -// -// NewImage = egCreateFilledImage(Width, Height, Image->HasAlpha, Color); -// if (NewImage == NULL) { -// egFreeImage(Image); -// return NULL; -// } -// Image->HasAlpha = FALSE; -// egComposeImage(NewImage, Image, 0, 0); -// egFreeImage(Image); -// -// return NewImage; -// } - // // misc internal functions // diff --git a/refind/config.c b/refind/config.c index 731adb7..573a5db 100644 --- a/refind/config.c +++ b/refind/config.c @@ -400,7 +400,7 @@ static BOOLEAN HandleBoolean(IN CHAR16 **TokenList, IN UINTN TokenCount) { static VOID SetDefaultByTime(IN CHAR16 **TokenList, OUT CHAR16 **Default) { EFI_STATUS Status; EFI_TIME CurrentTime; - UINTN StartTime = LAST_MINUTE + 1, EndTime = LAST_MINUTE + 1, Now; + UINTN StartTime, EndTime, Now; BOOLEAN SetIt = FALSE; StartTime = HandleTime(TokenList[2]); @@ -770,11 +770,13 @@ static VOID AddSubmenu(LOADER_ENTRY *Entry, REFIT_FILE *File, REFIT_VOLUME *Volu } else if ((StriCmp(TokenList[0], L"volume") == 0) && (TokenCount > 1)) { if (FindVolume(&Volume, TokenList[1])) { - MyFreePool(SubEntry->me.Title); - SubEntry->me.Title = AllocateZeroPool(256 * sizeof(CHAR16)); - SPrint(SubEntry->me.Title, 255, L"Boot %s from %s", (Title != NULL) ? Title : L"Unknown", Volume->VolName); - SubEntry->me.BadgeImage = Volume->VolBadgeImage; - SubEntry->VolName = Volume->VolName; + if ((Volume != NULL) && (Volume->IsReadable) && (Volume->RootDir)) { + MyFreePool(SubEntry->me.Title); + SubEntry->me.Title = AllocateZeroPool(256 * sizeof(CHAR16)); + SPrint(SubEntry->me.Title, 255, L"Boot %s from %s", (Title != NULL) ? Title : L"Unknown", Volume->VolName); + SubEntry->me.BadgeImage = Volume->VolBadgeImage; + SubEntry->VolName = Volume->VolName; + } // if volume is readable } // if match found } else if (StriCmp(TokenList[0], L"initrd") == 0) { @@ -851,11 +853,13 @@ static LOADER_ENTRY * AddStanzaEntries(REFIT_FILE *File, REFIT_VOLUME *Volume, C } else if ((StriCmp(TokenList[0], L"volume") == 0) && (TokenCount > 1)) { if (FindVolume(&CurrentVolume, TokenList[1])) { - MyFreePool(Entry->me.Title); - Entry->me.Title = AllocateZeroPool(256 * sizeof(CHAR16)); - SPrint(Entry->me.Title, 255, L"Boot %s from %s", (Title != NULL) ? Title : L"Unknown", CurrentVolume->VolName); - Entry->me.BadgeImage = CurrentVolume->VolBadgeImage; - Entry->VolName = CurrentVolume->VolName; + if ((CurrentVolume != NULL) && (CurrentVolume->IsReadable) && (CurrentVolume->RootDir)) { + MyFreePool(Entry->me.Title); + Entry->me.Title = AllocateZeroPool(256 * sizeof(CHAR16)); + SPrint(Entry->me.Title, 255, L"Boot %s from %s", (Title != NULL) ? Title : L"Unknown", CurrentVolume->VolName); + Entry->me.BadgeImage = CurrentVolume->VolBadgeImage; + Entry->VolName = CurrentVolume->VolName; + } // if volume is readable } // if match found } else if ((StriCmp(TokenList[0], L"icon") == 0) && (TokenCount > 1)) { diff --git a/refind/global.h b/refind/global.h index 4824445..b0f10ed 100644 --- a/refind/global.h +++ b/refind/global.h @@ -131,7 +131,8 @@ #define FS_TYPE_HFSPLUS 8 #define FS_TYPE_REISERFS 9 #define FS_TYPE_BTRFS 10 -#define FS_TYPE_ISO9660 11 +#define FS_TYPE_XFS 11 +#define FS_TYPE_ISO9660 12 // How to scale banner images #define BANNER_NOSCALE 0 diff --git a/refind/lib.c b/refind/lib.c index 19e140a..492541a 100644 --- a/refind/lib.c +++ b/refind/lib.c @@ -50,6 +50,7 @@ #include "../include/RemovableMedia.h" #include "gpt.h" #include "config.h" +#include "../EfiLib/LegacyBios.h" #ifdef __MAKEWITH_GNUEFI #define EfiReallocatePool ReallocatePool @@ -75,6 +76,7 @@ EFI_DEVICE_PATH EndDevicePath[] = { #define REISER2FS_SUPER_MAGIC_STRING "ReIsEr2Fs" #define REISER2FS_JR_SUPER_MAGIC_STRING "ReIsEr3Fs" #define BTRFS_SIGNATURE "_BHRfS_M" +#define XFS_SIGNATURE "XFSB" #define NTFS_SIGNATURE "NTFS " // variables @@ -460,6 +462,9 @@ static CHAR16 *FSTypeName(IN UINT32 TypeCode) { case FS_TYPE_BTRFS: retval = L" Btrfs"; break; + case FS_TYPE_XFS: + retval = L" XFS"; + break; case FS_TYPE_ISO9660: retval = L" ISO-9660"; break; @@ -494,33 +499,6 @@ static VOID SetFilesystemData(IN UINT8 *Buffer, IN UINTN BufferSize, IN OUT REFI SetMem(&(Volume->VolUuid), sizeof(EFI_GUID), 0); Volume->FSType = FS_TYPE_UNKNOWN; - if (BufferSize >= 512) { - - // Search for NTFS, FAT, and MBR/EBR. - // These all have 0xAA55 at the end of the first sector, but FAT and - // MBR/EBR are not easily distinguished. Thus, we first check to see - // if the "volume" is in fact a disk device; then look for NTFS - // "magic"; and then check to see if the volume can be mounted, thus - // relying on the EFI's built-in FAT driver to identify FAT. - Magic16 = (UINT16*) (Buffer + 510); - if (*Magic16 == FAT_MAGIC) { - MagicString = (char*) (Buffer + 3); - // Confusingly, "LogicalPartition" refers to the presence of a - // partition table, not an MBR logical partition. - if (Volume->BlockIO->Media->LogicalPartition) { - Volume->FSType = FS_TYPE_WHOLEDISK; - } else if (CompareMem(MagicString, NTFS_SIGNATURE, 8) == 0) { - Volume->FSType = FS_TYPE_NTFS; - CopyMem(&(Volume->VolUuid), Buffer + 0x48, sizeof(UINT64)); - } else { - RootDir = LibOpenRoot(Volume->DeviceHandle); - if (RootDir != NULL) - Volume->FSType = FS_TYPE_FAT; - } // if/elseif/else - return; - } // if - } // search for FAT and NTFS magic - if (BufferSize >= (1024 + 100)) { Magic16 = (UINT16*) (Buffer + 1024 + 56); if (*Magic16 == EXT2_SUPER_MAGIC) { // ext2/3/4 @@ -557,6 +535,14 @@ static VOID SetFilesystemData(IN UINT8 *Buffer, IN UINTN BufferSize, IN OUT REFI } // if } // search for Btrfs magic + if (BufferSize >= 512) { + MagicString = (char*) Buffer; + if (CompareMem(MagicString, XFS_SIGNATURE, 4) == 0) { + Volume->FSType = FS_TYPE_XFS; + return; + } + } // search for XFS magic + if (BufferSize >= (1024 + 2)) { Magic16 = (UINT16*) (Buffer + 1024); if ((*Magic16 == HFSPLUS_MAGIC1) || (*Magic16 == HFSPLUS_MAGIC2)) { @@ -565,7 +551,32 @@ static VOID SetFilesystemData(IN UINT8 *Buffer, IN UINTN BufferSize, IN OUT REFI } } // search for HFS+ magic - } // if (Buffer != NULL) + if (BufferSize >= 512) { + // Search for NTFS, FAT, and MBR/EBR. + // These all have 0xAA55 at the end of the first sector, but FAT and + // MBR/EBR are not easily distinguished. Thus, we first look for NTFS + // "magic"; then check to see if the volume can be mounted, thus + // relying on the EFI's built-in FAT driver to identify FAT; and then + // check to see if the "volume" is in fact a whole-disk device. + Magic16 = (UINT16*) (Buffer + 510); + if (*Magic16 == FAT_MAGIC) { + MagicString = (char*) (Buffer + 3); + if (CompareMem(MagicString, NTFS_SIGNATURE, 8) == 0) { + Volume->FSType = FS_TYPE_NTFS; + CopyMem(&(Volume->VolUuid), Buffer + 0x48, sizeof(UINT64)); + } else { + RootDir = LibOpenRoot(Volume->DeviceHandle); + if (RootDir != NULL) { + Volume->FSType = FS_TYPE_FAT; + } else if (!Volume->BlockIO->Media->LogicalPartition) { + Volume->FSType = FS_TYPE_WHOLEDISK; + } // if/elseif/else + } // if/else + return; + } // if + } // search for FAT and NTFS magic + + } // if ((Buffer != NULL) && (Volume != NULL)) } // UINT32 SetFilesystemData() @@ -593,11 +604,7 @@ static VOID ScanVolumeBootcode(REFIT_VOLUME *Volume, BOOLEAN *Bootable) Volume->BlockIOOffset, SAMPLE_SIZE, Buffer); if (!EFI_ERROR(Status)) { -// if (Volume->BlockIO->Media->LogicalPartition) -// Print(L"Skipping; whole disk!\n"); -// else - SetFilesystemData(Buffer, SAMPLE_SIZE, Volume); -// PauseForKey(); + SetFilesystemData(Buffer, SAMPLE_SIZE, Volume); if ((*((UINT16 *)(Buffer + 510)) == 0xaa55 && Buffer[0] != 0) && (FindMem(Buffer, 512, "EXFAT", 5) == -1)) { *Bootable = TRUE; Volume->HasBootCode = TRUE; @@ -1288,15 +1295,17 @@ VOID ReinitVolumes(VOID) BOOLEAN FileExists(IN EFI_FILE *BaseDir, IN CHAR16 *RelativePath) { - EFI_STATUS Status; - EFI_FILE_HANDLE TestFile; - - Status = refit_call5_wrapper(BaseDir->Open, BaseDir, &TestFile, RelativePath, EFI_FILE_MODE_READ, 0); - if (Status == EFI_SUCCESS) { - refit_call1_wrapper(TestFile->Close, TestFile); - return TRUE; - } - return FALSE; + EFI_STATUS Status; + EFI_FILE_HANDLE TestFile; + + if (BaseDir != NULL) { + Status = refit_call5_wrapper(BaseDir->Open, BaseDir, &TestFile, RelativePath, EFI_FILE_MODE_READ, 0); + if (Status == EFI_SUCCESS) { + refit_call1_wrapper(TestFile->Close, TestFile); + return TRUE; + } + } + return FALSE; } EFI_STATUS DirNextEntry(IN EFI_FILE *Directory, IN OUT EFI_FILE_INFO **DirEntry, IN UINTN FilterMode) diff --git a/refind/main.c b/refind/main.c index 3c94ad3..ffbf03e 100644 --- a/refind/main.c +++ b/refind/main.c @@ -166,7 +166,7 @@ static VOID AboutrEFInd(VOID) if (AboutMenu.EntryCount == 0) { AboutMenu.TitleImage = BuiltinIcon(BUILTIN_ICON_FUNC_ABOUT); - AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.8.6.4"); + AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.8.6.6"); AddMenuInfoLine(&AboutMenu, L""); AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2006-2010 Christoph Pfisterer"); AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2012-2015 Roderick W. Smith"); @@ -803,7 +803,6 @@ VOID GenerateSubScreen(LOADER_ENTRY *Entry, IN REFIT_VOLUME *Volume) { SubEntry = InitializeLoaderEntry(Entry); if (SubEntry != NULL) { SubEntry->me.Title = L"Boot Linux for a 17\" iMac or a 15\" MacBook Pro (*)"; - SubEntry->UseGraphicsMode = TRUE; SubEntry->LoadOptions = L"-d 0 i17"; SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_ELILO; AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry); @@ -812,7 +811,6 @@ VOID GenerateSubScreen(LOADER_ENTRY *Entry, IN REFIT_VOLUME *Volume) { SubEntry = InitializeLoaderEntry(Entry); if (SubEntry != NULL) { SubEntry->me.Title = L"Boot Linux for a 20\" iMac (*)"; - SubEntry->UseGraphicsMode = TRUE; SubEntry->LoadOptions = L"-d 0 i20"; SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_ELILO; AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry); @@ -821,7 +819,6 @@ VOID GenerateSubScreen(LOADER_ENTRY *Entry, IN REFIT_VOLUME *Volume) { SubEntry = InitializeLoaderEntry(Entry); if (SubEntry != NULL) { SubEntry->me.Title = L"Boot Linux for a Mac Mini (*)"; - SubEntry->UseGraphicsMode = TRUE; SubEntry->LoadOptions = L"-d 0 mini"; SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_ELILO; AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry); @@ -853,7 +850,6 @@ VOID GenerateSubScreen(LOADER_ENTRY *Entry, IN REFIT_VOLUME *Volume) { SubEntry = InitializeLoaderEntry(Entry); if (SubEntry != NULL) { SubEntry->me.Title = L"Run XOM in text mode"; - SubEntry->UseGraphicsMode = FALSE; SubEntry->LoadOptions = L"-v"; SubEntry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_WINDOWS; AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry); @@ -1008,7 +1004,6 @@ VOID SetLoaderDefaults(LOADER_ENTRY *Entry, CHAR16 *LoaderPath, REFIT_VOLUME *Vo Entry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_WINDOWS; } else if (StriCmp(NameClues, L"xom.efi") == 0) { MergeStrings(&OSIconName, L"xom,win,win8", L','); - Entry->UseGraphicsMode = TRUE; Entry->OSType = 'X'; ShortcutLetter = 'W'; Entry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_WINDOWS; diff --git a/refind/menu.c b/refind/menu.c index e55bcf4..55511be 100644 --- a/refind/menu.c +++ b/refind/menu.c @@ -761,12 +761,13 @@ static UINT8 AverageBrightness(EG_IMAGE *Image) { UINTN i; UINTN Sum = 0; - if (Image != NULL) { + if ((Image != NULL) && ((Image->Width * Image->Height) != 0)) { for (i = 0; i < (Image->Width * Image->Height); i++) { Sum += (Image->PixelData[i].r + Image->PixelData[i].g + Image->PixelData[i].b); } + Sum /= (Image->Width * Image->Height * 3); } // if - return (UINT8) (Sum / (Image->Width * Image->Height * 3)); + return (UINT8) Sum; } // UINT8 AverageBrightness() // Display text against the screen's background image. Special case: If Text is NULL diff --git a/refind/screen.c b/refind/screen.c index 655057f..29d11c8 100644 --- a/refind/screen.c +++ b/refind/screen.c @@ -572,12 +572,14 @@ VOID BltImageCompositeBadge(IN EG_IMAGE *BaseImage, IN EG_IMAGE *TopImage, IN EG } // blit to screen and clean up - if (CompImage->HasAlpha) - egDrawImageWithTransparency(CompImage, NULL, XPos, YPos, CompImage->Width, CompImage->Height); - else - egDrawImage(CompImage, XPos, YPos); - egFreeImage(CompImage); - GraphicsScreenDirty = TRUE; + if (CompImage != NULL) { + if (CompImage->HasAlpha) + egDrawImageWithTransparency(CompImage, NULL, XPos, YPos, CompImage->Width, CompImage->Height); + else + egDrawImage(CompImage, XPos, YPos); + egFreeImage(CompImage); + GraphicsScreenDirty = TRUE; + } } // Line-editing functions borrowed from gummiboot (cursor_left(), cursor_right(), & line_edit()).