diff options
author | Jan Janssen <medhefgo@web.de> | 2018-01-07 11:53:34 +0100 |
---|---|---|
committer | Jan Janssen <medhefgo@web.de> | 2018-01-28 17:20:41 +0100 |
commit | 33d4ba32c93cba64832ce73c50cfd316200c0be3 (patch) | |
tree | 68c3b6fafdd531d6a1add0a53241bc504a3b5e07 /src/boot | |
parent | 46659f7deb962f55c728e70597e37c2a3ab6326d (diff) | |
download | systemd-33d4ba32c93cba64832ce73c50cfd316200c0be3.tar.gz |
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.
Diffstat (limited to 'src/boot')
-rw-r--r-- | src/boot/efi/boot.c | 18 | ||||
-rw-r--r-- | src/boot/efi/shim.c | 5 | ||||
-rw-r--r-- | src/boot/efi/util.c | 21 | ||||
-rw-r--r-- | src/boot/efi/util.h | 2 |
4 files changed, 23 insertions, 23 deletions
diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c index 06331da2d4..9d5ea6ed93 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 6d7d814c5c..7c479048c1 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 b165f31005..bff8ba8d20 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 35150aea76..49632ffcbc 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 |