From 96cf3c015c3a296e53d1d5901efaf889bf83d00d Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Mon, 13 Apr 2015 19:55:25 -0400 Subject: Align the sections we're loading, and check for validity /after/ discarding. Turns out a) the codegen on aarch64 generates code that has real alignment needs, and b) if we check the length of discardable sections before discarding them, we error for no reason. So do the error checking in the right order, and always enforce some alignment because we know we have to. Signed-off-by: Peter Jones --- include/PeImage.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/PeImage.h b/include/PeImage.h index 133e11e6..05f32ea2 100644 --- a/include/PeImage.h +++ b/include/PeImage.h @@ -778,6 +778,7 @@ typedef struct { UINTN SizeOfHeaders; UINT16 ImageType; UINT16 NumberOfSections; + UINT32 SectionAlignment; EFI_IMAGE_SECTION_HEADER *FirstSection; EFI_IMAGE_DATA_DIRECTORY *RelocDir; EFI_IMAGE_DATA_DIRECTORY *SecDir; -- cgit v1.2.3 From 1f23ecc3000b14c02cbaf47a819ed89ac93ec12e Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Mon, 13 Apr 2015 19:55:25 -0400 Subject: Make lib/ build right with the cflags it should be using... ... but isn't. Signed-off-by: Peter Jones --- include/console.h | 9 ++++++--- include/guid.h | 5 ----- lib/configtable.c | 4 ++-- lib/console.c | 23 +++++++++++++---------- lib/execute.c | 2 +- lib/guid.c | 25 ------------------------- lib/shell.c | 2 +- 7 files changed, 23 insertions(+), 47 deletions(-) (limited to 'include') diff --git a/include/console.h b/include/console.h index 9c793ea5..ecaa73f5 100644 --- a/include/console.h +++ b/include/console.h @@ -4,13 +4,16 @@ EFI_STATUS console_get_keystroke(EFI_INPUT_KEY *key); void -console_print_box_at(CHAR16 *str_arr[], int highlight, int start_col, int start_row, int size_cols, int size_rows, int offset, int lines); +console_print_box_at(CHAR16 *str_arr[], unsigned int highlight, + unsigned int start_col, unsigned int start_row, + unsigned int size_cols, unsigned int size_rows, + int offset, unsigned int lines); void -console_print_box(CHAR16 *str_arr[], int highlight); +console_print_box(CHAR16 *str_arr[], unsigned int highlight); int console_yes_no(CHAR16 *str_arr[]); int -console_select(CHAR16 *title[], CHAR16* selectors[], int start); +console_select(CHAR16 *title[], CHAR16* selectors[], unsigned int start); void console_errorbox(CHAR16 *err); void diff --git a/include/guid.h b/include/guid.h index 3c58be0b..86b709b8 100644 --- a/include/guid.h +++ b/include/guid.h @@ -1,10 +1,5 @@ #include -#ifndef BUILD_EFI -const char *guid_to_str(EFI_GUID *guid); -void str_to_guid(const char *str, EFI_GUID *guid); -#endif - extern EFI_GUID GV_GUID; extern EFI_GUID SIG_DB; extern EFI_GUID X509_GUID; diff --git a/lib/configtable.c b/lib/configtable.c index e2d92bf0..edf2ed74 100644 --- a/lib/configtable.c +++ b/lib/configtable.c @@ -14,7 +14,7 @@ void * configtable_get_table(EFI_GUID *guid) { - int i; + unsigned int i; for (i = 0; i < ST->NumberOfTableEntries; i++) { EFI_CONFIGURATION_TABLE *CT = &ST->ConfigurationTable[i]; @@ -82,7 +82,7 @@ configtable_find_image(const EFI_DEVICE_PATH *DevicePath) } EFI_DEVICE_PATH *dp = (EFI_DEVICE_PATH *)(e->Data + skip), *dpn = dp; if (dp->Type == 0 || dp->Type > 6 || dp->SubType == 0 - || (((dp->Length[1] << 8) + dp->Length[0]) > e->InfoSize)) { + || ((unsigned)((dp->Length[1] << 8) + dp->Length[0]) > e->InfoSize)) { /* Parse error, table corrupt, bail */ Print(L"Image Execution Information table corrupt\n"); break; diff --git a/lib/console.c b/lib/console.c index fd8cc5c8..e70ab485 100644 --- a/lib/console.c +++ b/lib/console.c @@ -33,7 +33,7 @@ count_lines(CHAR16 *str_arr[]) static void SetMem16(CHAR16 *dst, UINT32 n, CHAR16 c) { - int i; + unsigned int i; for (i = 0; i < n/2; i++) { dst[i] = c; @@ -55,9 +55,12 @@ console_get_keystroke(EFI_INPUT_KEY *key) } void -console_print_box_at(CHAR16 *str_arr[], int highlight, int start_col, int start_row, int size_cols, int size_rows, int offset, int lines) +console_print_box_at(CHAR16 *str_arr[], unsigned int highlight, + unsigned int start_col, unsigned int start_row, + unsigned int size_cols, unsigned int size_rows, + int offset, unsigned int lines) { - int i; + unsigned int i; SIMPLE_TEXT_OUTPUT_INTERFACE *co = ST->ConOut; UINTN rows, cols; CHAR16 *Line; @@ -124,7 +127,7 @@ console_print_box_at(CHAR16 *str_arr[], int highlight, int start_col, int start_ for (i = start_row + 1; i < size_rows + start_row - 1; i++) { - int line = i - start; + unsigned int line = i - start; SetMem16 (Line, size_cols*2, L' '); Line[0] = BOXDRAW_VERTICAL; @@ -160,7 +163,7 @@ console_print_box_at(CHAR16 *str_arr[], int highlight, int start_col, int start_ } void -console_print_box(CHAR16 *str_arr[], int highlight) +console_print_box(CHAR16 *str_arr[], unsigned int highlight) { SIMPLE_TEXT_OUTPUT_MODE SavedConsoleMode; SIMPLE_TEXT_OUTPUT_INTERFACE *co = ST->ConOut; @@ -181,17 +184,17 @@ console_print_box(CHAR16 *str_arr[], int highlight) } int -console_select(CHAR16 *title[], CHAR16* selectors[], int start) +console_select(CHAR16 *title[], CHAR16* selectors[], unsigned int start) { SIMPLE_TEXT_OUTPUT_MODE SavedConsoleMode; SIMPLE_TEXT_OUTPUT_INTERFACE *co = ST->ConOut; EFI_INPUT_KEY k; EFI_STATUS status; - int selector; - int selector_lines = count_lines(selectors); + unsigned int selector; + unsigned int selector_lines = count_lines(selectors); int selector_max_cols = 0; - int i, offs_col, offs_row, size_cols, size_rows, lines; - int selector_offset; + unsigned int i, offs_col, offs_row, size_cols, size_rows, lines; + unsigned int selector_offset; UINTN cols, rows; uefi_call_wrapper(co->QueryMode, 4, co, co->Mode->Mode, &cols, &rows); diff --git a/lib/execute.c b/lib/execute.c index 42d71c87..89328c68 100644 --- a/lib/execute.c +++ b/lib/execute.c @@ -51,7 +51,7 @@ generate_path(CHAR16* name, EFI_LOADED_IMAGE *li, EFI_DEVICE_PATH **path, CHAR16 EFI_STATUS efi_status = EFI_SUCCESS; CHAR16 *devpathstr = DevicePathToStr(li->FilePath), *found = NULL; - int i; + unsigned int i; for (i = 0; i < StrLen(devpathstr); i++) { if (devpathstr[i] == '/') diff --git a/lib/guid.c b/lib/guid.c index c97a7ca8..5f5a03ff 100644 --- a/lib/guid.c +++ b/lib/guid.c @@ -6,31 +6,6 @@ #include -#ifndef BUILD_EFI -/* EFI has %g for this, so it's only needed in platform c */ -const char *guid_to_str(EFI_GUID *guid) -{ - static char str[256]; - - sprintf(str, "%08x-%04hx-%04hx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx", - guid->Data1, guid->Data2, guid->Data3, - guid->Data4[0], guid->Data4[1], guid->Data4[2], - guid->Data4[3], guid->Data4[4], guid->Data4[5], - guid->Data4[6], guid->Data4[7]); - - return str; -} - -void str_to_guid(const char *str, EFI_GUID *guid) -{ - sscanf(str, "%8x-%4hx-%4hx-%2hhx%2hhx-%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx", - &guid->Data1, &guid->Data2, &guid->Data3, - guid->Data4, guid->Data4 + 1, guid->Data4 + 2, - guid->Data4 + 3, guid->Data4 + 4, guid->Data4 + 5, - guid->Data4 + 6, guid->Data4 + 7); -} -#endif - /* all the necessary guids */ EFI_GUID GV_GUID = EFI_GLOBAL_VARIABLE; EFI_GUID SIG_DB = { 0xd719b2cb, 0x3d3a, 0x4596, {0xa3, 0xbc, 0xda, 0xd0, 0xe, 0x67, 0x65, 0x6f }}; diff --git a/lib/shell.c b/lib/shell.c index 7337834a..afd3952c 100644 --- a/lib/shell.c +++ b/lib/shell.c @@ -13,7 +13,7 @@ EFI_STATUS argsplit(EFI_HANDLE image, int *argc, CHAR16*** ARGV) { - int i, count = 1; + unsigned int i, count = 1; EFI_STATUS status; EFI_LOADED_IMAGE *info; CHAR16 *start; -- cgit v1.2.3 From 1fefa29c34b8177779a237e26984ae973adf23e9 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 16 Jun 2015 11:41:32 -0400 Subject: Fix console_print_box*() parameters. When we made lib build with the correct CFLAGS, it inherited -Werror=sign-compare, and I fixed up some parameters on console_print_box() and console_print_box_at() to avoid sign comparison errors. The fixups were *completely wrong*, as some behavior relies on negative values. So this fixes them in a completely different way, by casting appropriately to signed types where we're doing comparisons. Signed-off-by: Peter Jones --- include/console.h | 10 +++++----- lib/console.c | 27 +++++++++++++-------------- 2 files changed, 18 insertions(+), 19 deletions(-) (limited to 'include') diff --git a/include/console.h b/include/console.h index ecaa73f5..d59e3b4f 100644 --- a/include/console.h +++ b/include/console.h @@ -4,12 +4,12 @@ EFI_STATUS console_get_keystroke(EFI_INPUT_KEY *key); void -console_print_box_at(CHAR16 *str_arr[], unsigned int highlight, - unsigned int start_col, unsigned int start_row, - unsigned int size_cols, unsigned int size_rows, - int offset, unsigned int lines); +console_print_box_at(CHAR16 *str_arr[], int highlight, + int start_col, int start_row, + int size_cols, int size_rows, + int offset, int lines); void -console_print_box(CHAR16 *str_arr[], unsigned int highlight); +console_print_box(CHAR16 *str_arr[], int highlight); int console_yes_no(CHAR16 *str_arr[]); int diff --git a/lib/console.c b/lib/console.c index e70ab485..b62fe4cc 100644 --- a/lib/console.c +++ b/lib/console.c @@ -55,12 +55,12 @@ console_get_keystroke(EFI_INPUT_KEY *key) } void -console_print_box_at(CHAR16 *str_arr[], unsigned int highlight, - unsigned int start_col, unsigned int start_row, - unsigned int size_cols, unsigned int size_rows, - int offset, unsigned int lines) +console_print_box_at(CHAR16 *str_arr[], int highlight, + int start_col, int start_row, + int size_cols, int size_rows, + int offset, int lines) { - unsigned int i; + int i; SIMPLE_TEXT_OUTPUT_INTERFACE *co = ST->ConOut; UINTN rows, cols; CHAR16 *Line; @@ -87,16 +87,16 @@ console_print_box_at(CHAR16 *str_arr[], unsigned int highlight, if (start_row < 0) start_row = 0; - if (start_col > cols || start_row > rows) { + if (start_col > (int)cols || start_row > (int)rows) { Print(L"Starting Position (%d,%d) is off screen\n", start_col, start_row); return; } - if (size_cols + start_col > cols) + if (size_cols + start_col > (int)cols) size_cols = cols - start_col; - if (size_rows + start_row > rows) + if (size_rows + start_row > (int)rows) size_rows = rows - start_row; - + if (lines > size_rows - 2) lines = size_rows - 2; @@ -124,10 +124,9 @@ console_print_box_at(CHAR16 *str_arr[], unsigned int highlight, else /* from top */ start = start_row + offset; - for (i = start_row + 1; i < size_rows + start_row - 1; i++) { - unsigned int line = i - start; + int line = i - start; SetMem16 (Line, size_cols*2, L' '); Line[0] = BOXDRAW_VERTICAL; @@ -143,11 +142,11 @@ console_print_box_at(CHAR16 *str_arr[], unsigned int highlight, CopyMem(Line + col + 1, s, min(len, size_cols - 2)*2); } - if (line >= 0 && line == highlight) + if (line >= 0 && line == highlight) uefi_call_wrapper(co->SetAttribute, 2, co, EFI_LIGHTGRAY | EFI_BACKGROUND_BLACK); uefi_call_wrapper(co->SetCursorPosition, 3, co, start_col, i); uefi_call_wrapper(co->OutputString, 2, co, Line); - if (line >= 0 && line == highlight) + if (line >= 0 && line == highlight) uefi_call_wrapper(co->SetAttribute, 2, co, EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE); } @@ -163,7 +162,7 @@ console_print_box_at(CHAR16 *str_arr[], unsigned int highlight, } void -console_print_box(CHAR16 *str_arr[], unsigned int highlight) +console_print_box(CHAR16 *str_arr[], int highlight) { SIMPLE_TEXT_OUTPUT_MODE SavedConsoleMode; SIMPLE_TEXT_OUTPUT_INTERFACE *co = ST->ConOut; -- cgit v1.2.3 From a8b6d058f06caab17d1ab5096c7077c813d47044 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 9 Jun 2016 15:32:37 -0400 Subject: shim: make the PE loader less overzealous on rejections --- include/PeImage.h | 52 +++++++++++++++--------------- shim.c | 96 ++++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 99 insertions(+), 49 deletions(-) (limited to 'include') diff --git a/include/PeImage.h b/include/PeImage.h index 05f32ea2..17f186c7 100644 --- a/include/PeImage.h +++ b/include/PeImage.h @@ -306,35 +306,35 @@ typedef struct { /// Size of EFI_IMAGE_SECTION_HEADER. /// #define EFI_IMAGE_SIZEOF_SECTION_HEADER 40 - + // // Section Flags Values // -#define EFI_IMAGE_SCN_TYPE_NO_PAD BIT3 ///< 0x00000008 ///< Reserved. -#define EFI_IMAGE_SCN_CNT_CODE BIT5 ///< 0x00000020 -#define EFI_IMAGE_SCN_CNT_INITIALIZED_DATA BIT6 ///< 0x00000040 -#define EFI_IMAGE_SCN_CNT_UNINITIALIZED_DATA BIT7 ///< 0x00000080 - -#define EFI_IMAGE_SCN_LNK_OTHER BIT8 ///< 0x00000100 ///< Reserved. -#define EFI_IMAGE_SCN_LNK_INFO BIT9 ///< 0x00000200 ///< Section contains comments or some other type of information. -#define EFI_IMAGE_SCN_LNK_REMOVE BIT11 ///< 0x00000800 ///< Section contents will not become part of image. -#define EFI_IMAGE_SCN_LNK_COMDAT BIT12 ///< 0x00001000 - -#define EFI_IMAGE_SCN_ALIGN_1BYTES BIT20 ///< 0x00100000 -#define EFI_IMAGE_SCN_ALIGN_2BYTES BIT21 ///< 0x00200000 -#define EFI_IMAGE_SCN_ALIGN_4BYTES (BIT20|BIT21) ///< 0x00300000 -#define EFI_IMAGE_SCN_ALIGN_8BYTES BIT22 ///< 0x00400000 -#define EFI_IMAGE_SCN_ALIGN_16BYTES (BIT20|BIT22) ///< 0x00500000 -#define EFI_IMAGE_SCN_ALIGN_32BYTES (BIT21|BIT22) ///< 0x00600000 -#define EFI_IMAGE_SCN_ALIGN_64BYTES (BIT20|BIT21|BIT22) ///< 0x00700000 - -#define EFI_IMAGE_SCN_MEM_DISCARDABLE BIT25 ///< 0x02000000 -#define EFI_IMAGE_SCN_MEM_NOT_CACHED BIT26 ///< 0x04000000 -#define EFI_IMAGE_SCN_MEM_NOT_PAGED BIT27 ///< 0x08000000 -#define EFI_IMAGE_SCN_MEM_SHARED BIT28 ///< 0x10000000 -#define EFI_IMAGE_SCN_MEM_EXECUTE BIT29 ///< 0x20000000 -#define EFI_IMAGE_SCN_MEM_READ BIT30 ///< 0x40000000 -#define EFI_IMAGE_SCN_MEM_WRITE BIT31 ///< 0x80000000 +#define EFI_IMAGE_SCN_TYPE_NO_PAD 0x00000008 ///< Reserved. +#define EFI_IMAGE_SCN_CNT_CODE 0x00000020 +#define EFI_IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 +#define EFI_IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 + +#define EFI_IMAGE_SCN_LNK_OTHER 0x00000100 ///< Reserved. +#define EFI_IMAGE_SCN_LNK_INFO 0x00000200 ///< Section contains comments or some other type of information. +#define EFI_IMAGE_SCN_LNK_REMOVE 0x00000800 ///< Section contents will not become part of image. +#define EFI_IMAGE_SCN_LNK_COMDAT 0x00001000 + +#define EFI_IMAGE_SCN_ALIGN_1BYTES 0x00100000 +#define EFI_IMAGE_SCN_ALIGN_2BYTES 0x00200000 +#define EFI_IMAGE_SCN_ALIGN_4BYTES 0x00300000 +#define EFI_IMAGE_SCN_ALIGN_8BYTES 0x00400000 +#define EFI_IMAGE_SCN_ALIGN_16BYTES 0x00500000 +#define EFI_IMAGE_SCN_ALIGN_32BYTES 0x00600000 +#define EFI_IMAGE_SCN_ALIGN_64BYTES 0x00700000 + +#define EFI_IMAGE_SCN_MEM_DISCARDABLE 0x02000000 +#define EFI_IMAGE_SCN_MEM_NOT_CACHED 0x04000000 +#define EFI_IMAGE_SCN_MEM_NOT_PAGED 0x08000000 +#define EFI_IMAGE_SCN_MEM_SHARED 0x10000000 +#define EFI_IMAGE_SCN_MEM_EXECUTE 0x20000000 +#define EFI_IMAGE_SCN_MEM_READ 0x40000000 +#define EFI_IMAGE_SCN_MEM_WRITE 0x80000000 /// /// Size of a Symbol Table Record. diff --git a/shim.c b/shim.c index 3232a171..ed01899c 100644 --- a/shim.c +++ b/shim.c @@ -1122,6 +1122,8 @@ static EFI_STATUS handle_image (void *data, unsigned int datasize, EFI_IMAGE_SECTION_HEADER *Section; char *base, *end; PE_COFF_LOADER_IMAGE_CONTEXT context; + unsigned int alignment; + int found_entry_point = 0; /* * The binary header contains relevant context and section pointers @@ -1147,8 +1149,26 @@ static EFI_STATUS handle_image (void *data, unsigned int datasize, } } + /* The spec says, uselessly, of SectionAlignment: + * ===== + * The alignment (in bytes) of sections when they are loaded into + * memory. It must be greater than or equal to FileAlignment. The + * default is the page size for the architecture. + * ===== + * Which doesn't tell you whose responsibility it is to enforce the + * "default", or when. It implies that the value in the field must + * be > FileAlignment (also poorly defined), but it appears visual + * studio will happily write 512 for FileAlignment (its default) and + * 0 for SectionAlignment, intending to imply PAGE_SIZE. + * + * We only support one page size, so if it's zero, nerf it to 4096. + */ + alignment = context.SectionAlignment; + if (!alignment) + alignment = 4096; + buffer = AllocatePool(context.ImageSize + context.SectionAlignment); - buffer = ALIGN_POINTER(buffer, context.SectionAlignment); + buffer = ALIGN_POINTER(buffer, alignment); if (!buffer) { perror(L"Failed to allocate image buffer\n"); @@ -1157,11 +1177,25 @@ static EFI_STATUS handle_image (void *data, unsigned int datasize, CopyMem(buffer, data, context.SizeOfHeaders); + entry_point = ImageAddress(buffer, context.ImageSize, context.EntryPoint); + if (!entry_point) { + perror(L"Entry point is invalid\n"); + FreePool(buffer); + return EFI_UNSUPPORTED; + } + + char *RelocBase, *RelocBaseEnd; - RelocBase = ImageAddress(buffer, datasize, + /* + * These are relative virtual addresses, so we have to check them + * against the image size, not the data size. + */ + RelocBase = ImageAddress(buffer, context.ImageSize, context.RelocDir->VirtualAddress); - /* RelocBaseEnd here is the address of the last byte of the table */ - RelocBaseEnd = ImageAddress(buffer, datasize, + /* + * RelocBaseEnd here is the address of the last byte of the table + */ + RelocBaseEnd = ImageAddress(buffer, context.ImageSize, context.RelocDir->VirtualAddress + context.RelocDir->Size - 1); @@ -1172,13 +1206,22 @@ static EFI_STATUS handle_image (void *data, unsigned int datasize, */ Section = context.FirstSection; for (i = 0; i < context.NumberOfSections; i++, Section++) { - size = Section->Misc.VirtualSize; - - if (size > Section->SizeOfRawData) - size = Section->SizeOfRawData; + base = ImageAddress (buffer, context.ImageSize, + Section->VirtualAddress); + end = ImageAddress (buffer, context.ImageSize, + Section->VirtualAddress + + Section->Misc.VirtualSize - 1); + + if (end < base) { + perror(L"Section %d has negative size\n", i); + FreePool(buffer); + return EFI_UNSUPPORTED; + } - base = ImageAddress (buffer, context.ImageSize, Section->VirtualAddress); - end = ImageAddress (buffer, context.ImageSize, Section->VirtualAddress + size - 1); + if (Section->VirtualAddress <= context.EntryPoint && + (Section->VirtualAddress + Section->SizeOfRawData - 1) + > context.EntryPoint) + found_entry_point++; /* We do want to process .reloc, but it's often marked * discardable, so we don't want to memcpy it. */ @@ -1199,27 +1242,32 @@ static EFI_STATUS handle_image (void *data, unsigned int datasize, } } - if (Section->Characteristics & 0x02000000) { - /* section has EFI_IMAGE_SCN_MEM_DISCARDABLE attr set */ + if (Section->Characteristics & EFI_IMAGE_SCN_MEM_DISCARDABLE) { continue; } - if (!base || !end) { - perror(L"Section %d has invalid size\n", i); + if (!base) { + perror(L"Section %d has invalid base address\n", i); + return EFI_UNSUPPORTED; + } + if (!end) { + perror(L"Section %d has zero size\n", i); return EFI_UNSUPPORTED; } - if (Section->VirtualAddress < context.SizeOfHeaders || - Section->PointerToRawData < context.SizeOfHeaders) { + if (!(Section->Characteristics & EFI_IMAGE_SCN_CNT_UNINITIALIZED_DATA) && + (Section->VirtualAddress < context.SizeOfHeaders || + Section->PointerToRawData < context.SizeOfHeaders)) { perror(L"Section %d is inside image headers\n", i); return EFI_UNSUPPORTED; } if (Section->SizeOfRawData > 0) - CopyMem(base, data + Section->PointerToRawData, size); + CopyMem(base, data + Section->PointerToRawData, Section->SizeOfRawData); - if (size < Section->Misc.VirtualSize) - ZeroMem (base + size, Section->Misc.VirtualSize - size); + if (Section->SizeOfRawData < Section->Misc.VirtualSize) + ZeroMem (base + Section->SizeOfRawData, + Section->Misc.VirtualSize - Section->SizeOfRawData); } if (context.NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) { @@ -1242,7 +1290,6 @@ static EFI_STATUS handle_image (void *data, unsigned int datasize, } } - entry_point = ImageAddress(buffer, context.ImageSize, context.EntryPoint); /* * grub needs to know its location and size in memory, so fix up * the loaded image protocol values @@ -1254,9 +1301,12 @@ static EFI_STATUS handle_image (void *data, unsigned int datasize, li->LoadOptions = load_options; li->LoadOptionsSize = load_options_size; - if (!entry_point) { - perror(L"Invalid entry point\n"); - FreePool(buffer); + if (!found_entry_point) { + perror(L"Entry point is not within sections\n"); + return EFI_UNSUPPORTED; + } + if (found_entry_point > 1) { + perror(L"%d sections contain entry point\n"); return EFI_UNSUPPORTED; } -- cgit v1.2.3