From fd47a4db0c84847ece5dbdbbf2a207cbf7639cd3 Mon Sep 17 00:00:00 2001 From: vit9696 Date: Tue, 9 Apr 2019 13:45:40 +0300 Subject: [PATCH] OpenCore: Avoid dangling booter protocol on load failure --- Application/Bootstrap/Bootstrap.inf | 1 + Platform/OpenCore/OpenCore.c | 24 ++++++++++++------------ Platform/OpenCore/OpenCoreKernel.c | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Application/Bootstrap/Bootstrap.inf b/Application/Bootstrap/Bootstrap.inf index 02cb8d0b..b2d3927e 100644 --- a/Application/Bootstrap/Bootstrap.inf +++ b/Application/Bootstrap/Bootstrap.inf @@ -55,3 +55,4 @@ MemoryAllocationLib OcDevicePathLib OcFileLib + OcStringLib diff --git a/Platform/OpenCore/OpenCore.c b/Platform/OpenCore/OpenCore.c index d4f2ae1b..639e5237 100644 --- a/Platform/OpenCore/OpenCore.c +++ b/Platform/OpenCore/OpenCore.c @@ -203,18 +203,6 @@ UefiMain ( return EFI_ALREADY_STARTED; } - BootstrapHandle = NULL; - Status = gBS->InstallMultipleProtocolInterfaces ( - &BootstrapHandle, - &gOcBootstrapProtocolGuid, - &mOpenCoreBootStrap, - NULL - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "OC: Failed to install bootstrap protocol - %r\n", Status)); - return Status; - } - LoadedImage = NULL; Status = gBS->HandleProtocol ( ImageHandle, @@ -227,6 +215,18 @@ UefiMain ( return EFI_NOT_FOUND; } + BootstrapHandle = NULL; + Status = gBS->InstallMultipleProtocolInterfaces ( + &BootstrapHandle, + &gOcBootstrapProtocolGuid, + &mOpenCoreBootStrap, + NULL + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "OC: Failed to install bootstrap protocol - %r\n", Status)); + return Status; + } + DebugPrintDevicePath (DEBUG_INFO, "OC: Booter path", LoadedImage->FilePath); if (LoadedImage->FilePath == NULL) { diff --git a/Platform/OpenCore/OpenCoreKernel.c b/Platform/OpenCore/OpenCoreKernel.c index e58e4fa9..b69e3c2b 100644 --- a/Platform/OpenCore/OpenCoreKernel.c +++ b/Platform/OpenCore/OpenCoreKernel.c @@ -59,7 +59,7 @@ OcKernelReadDarwinVersion ( Offset += L_STR_LEN ("Darwin Kernel Version "); for (Index = 0; Index < DarwinVersionSize - 1; ++Index, ++Offset) { - if (Offset >= KernelSize || Kernel[Offset] == ':') { + if ((UINT32) Offset >= KernelSize || Kernel[Offset] == ':') { break; } DarwinVersion[Index] = (CHAR8) Kernel[Offset];