From: Jan Janssen Date: Sun, 7 Jan 2018 10:53:34 +0000 (+0100) Subject: systemd-boot: Return EFI_STATUS instead of INTN for file_read() X-Git-Tag: v239~576^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=33d4ba32c93cba64832ce73c50cfd316200c0be3;p=thirdparty%2Fsystemd.git systemd-boot: Return EFI_STATUS instead of INTN for file_read() file_read() wants to return both a EFI_STATUS (INTN) and a file length (UINTN). This seems rather fishy for either large files or when returning errors (which are defined as positive numbers). Let's just be more clear and return EFI_STATUS and let the file length be a pointer. --- diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c index 06331da2d41..9d5ea6ed93e 100644 --- a/src/boot/efi/boot.c +++ b/src/boot/efi/boot.c @@ -1142,11 +1142,10 @@ static VOID config_entry_add_from_file(Config *config, EFI_HANDLE *device, CHAR1 static VOID config_load_defaults(Config *config, EFI_FILE *root_dir) { CHAR8 *content = NULL; UINTN sec; - UINTN len; EFI_STATUS err; - len = file_read(root_dir, L"\\loader\\loader.conf", 0, 0, &content); - if (len > 0) + err = file_read(root_dir, L"\\loader\\loader.conf", 0, 0, &content, NULL); + if (!EFI_ERROR(err)) config_defaults_load_from_file(config, content); FreePool(content); @@ -1190,8 +1189,8 @@ static VOID config_load_entries(Config *config, EFI_HANDLE *device, EFI_FILE *ro if (StrnCmp(f->FileName, L"auto-", 5) == 0) continue; - len = file_read(entries_dir, f->FileName, 0, 0, &content); - if (len > 0) + err = file_read(entries_dir, f->FileName, 0, 0, &content, NULL); + if (!EFI_ERROR(err)) config_entry_add_from_file(config, device, f->FileName, content, loaded_image_path); FreePool(content); } @@ -1526,8 +1525,8 @@ static VOID config_entry_add_linux( Config *config, EFI_LOADED_IMAGE *loaded_ima if (EFI_ERROR(err)) continue; - len = file_read(linux_dir, f->FileName, offs[0], szs[0], &content); - if (len <= 0) + err = file_read(linux_dir, f->FileName, offs[0], szs[0], &content, NULL); + if (EFI_ERROR(err)) continue; /* read properties from the embedded os-release file */ @@ -1568,9 +1567,10 @@ static VOID config_entry_add_linux( Config *config, EFI_LOADED_IMAGE *loaded_ima entry = config_entry_add_loader(config, loaded_image->DeviceHandle, LOADER_LINUX, conf, 'l', os_name, path); FreePool(content); + content = NULL; /* read the embedded cmdline file */ - len = file_read(linux_dir, f->FileName, offs[1], szs[1] - 1 , &content); - if (len > 0) { + err = file_read(linux_dir, f->FileName, offs[1], szs[1] - 1, &content, NULL); + if (!EFI_ERROR(err)) { cmdline = stra_to_str(content); entry->options = cmdline; cmdline = NULL; diff --git a/src/boot/efi/shim.c b/src/boot/efi/shim.c index 6d7d814c5cc..7c479048c10 100644 --- a/src/boot/efi/shim.c +++ b/src/boot/efi/shim.c @@ -179,7 +179,10 @@ static EFIAPI EFI_STATUS security_policy_authentication (const EFI_SECURITY_PROT dev_path_str = DevicePathToStr(dev_path); FreePool(dev_path); - file_size = file_read(root, dev_path_str, 0, 0, &file_buffer); + status = file_read(root, dev_path_str, 0, 0, &file_buffer, &file_size); + if (EFI_ERROR(status)) + return status; + FreePool(dev_path_str); uefi_call_wrapper(root->Close, 1, root); diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c index b165f31005f..bff8ba8d206 100644 --- a/src/boot/efi/util.c +++ b/src/boot/efi/util.c @@ -304,12 +304,10 @@ CHAR8 *strchra(CHAR8 *s, CHAR8 c) { return NULL; } -INTN file_read(EFI_FILE_HANDLE dir, CHAR16 *name, UINTN off, UINTN size, CHAR8 **content) { +EFI_STATUS file_read(EFI_FILE_HANDLE dir, CHAR16 *name, UINTN off, UINTN size, CHAR8 **content, UINTN *content_size) { EFI_FILE_HANDLE handle; CHAR8 *buf; - UINTN buflen; EFI_STATUS err; - UINTN len; err = uefi_call_wrapper(dir->Open, 5, dir, &handle, name, EFI_FILE_MODE_READ, 0ULL); if (EFI_ERROR(err)) @@ -319,10 +317,9 @@ INTN file_read(EFI_FILE_HANDLE dir, CHAR16 *name, UINTN off, UINTN size, CHAR8 * EFI_FILE_INFO *info; info = LibFileInfo(handle); - buflen = info->FileSize+1; + size = info->FileSize+1; FreePool(info); - } else - buflen = size; + } if (off > 0) { err = uefi_call_wrapper(handle->SetPosition, 2, handle, off); @@ -330,17 +327,17 @@ INTN file_read(EFI_FILE_HANDLE dir, CHAR16 *name, UINTN off, UINTN size, CHAR8 * return err; } - buf = AllocatePool(buflen); - err = uefi_call_wrapper(handle->Read, 3, handle, &buflen, buf); + buf = AllocatePool(size); + err = uefi_call_wrapper(handle->Read, 3, handle, &size, buf); if (!EFI_ERROR(err)) { - buf[buflen] = '\0'; + buf[size] = '\0'; *content = buf; - len = buflen; + if (content_size) + *content_size = size; } else { - len = err; FreePool(buf); } uefi_call_wrapper(handle->Close, 1, handle); - return len; + return err; } diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h index 35150aea769..49632ffcbc4 100644 --- a/src/boot/efi/util.h +++ b/src/boot/efi/util.h @@ -45,5 +45,5 @@ CHAR8 *strchra(CHAR8 *s, CHAR8 c); CHAR16 *stra_to_path(CHAR8 *stra); CHAR16 *stra_to_str(CHAR8 *stra); -INTN file_read(EFI_FILE_HANDLE dir, CHAR16 *name, UINTN off, UINTN size, CHAR8 **content); +EFI_STATUS file_read(EFI_FILE_HANDLE dir, CHAR16 *name, UINTN off, UINTN size, CHAR8 **content, UINTN *content_size); #endif