From 680c004f4a8cb0b8b6ca5ea3450f9a982391bf2d Mon Sep 17 00:00:00 2001 From: tkchia Date: Mon, 29 May 2023 18:01:49 +0000 Subject: [PATCH] [metal] Fix crash under UEFI when command line string is NULL --- libc/runtime/efimain.greg.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libc/runtime/efimain.greg.c b/libc/runtime/efimain.greg.c index 8081ab9be..783c87399 100644 --- a/libc/runtime/efimain.greg.c +++ b/libc/runtime/efimain.greg.c @@ -153,6 +153,7 @@ __msabi noasan EFI_STATUS EfiMain(EFI_HANDLE ImageHandle, uint64_t Address; uintptr_t Args, MapKey, DescSize; uint64_t p, pe, cr4, *m, *pd, *sp, *pml4t, *pdt1, *pdt2, *pdpt1, *pdpt2; + const char16_t *CmdLine; /* * Allocates and clears PC-compatible memory and copies image. Marks the @@ -190,7 +191,9 @@ __msabi noasan EFI_STATUS EfiMain(EFI_HANDLE ImageHandle, ArgBlock = (struct EfiArgs *)0x7e000; SystemTable->BootServices->HandleProtocol(ImageHandle, &kEfiLoadedImageProtocol, &ImgInfo); - Args = GetDosArgv(ImgInfo->LoadOptions, ArgBlock->ArgBlock, + CmdLine = (const char16_t *)ImgInfo->LoadOptions; + if (!CmdLine || !CmdLine[0]) CmdLine = u"BOOTX64.EFI"; + Args = GetDosArgv(CmdLine, ArgBlock->ArgBlock, sizeof(ArgBlock->ArgBlock), ArgBlock->Args, ARRAYLEN(ArgBlock->Args));