]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemd-boot: Return EFI_STATUS instead of INTN for file_read()
authorJan Janssen <medhefgo@web.de>
Sun, 7 Jan 2018 10:53:34 +0000 (11:53 +0100)
committerJan Janssen <medhefgo@web.de>
Sun, 28 Jan 2018 16:20:41 +0000 (17:20 +0100)
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.

src/boot/efi/boot.c
src/boot/efi/shim.c
src/boot/efi/util.c
src/boot/efi/util.h

index 06331da2d41c2fc07c5ac06a759fe7152b6a758e..9d5ea6ed93e14cb3869dd2f95e5defe45d2f4a01 100644 (file)
@@ -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;
index 6d7d814c5cc57a7adf0aa23ee307ee50b3d00eca..7c479048c102ed88fb1f50428c61599bdeaff688 100644 (file)
@@ -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);
 
index b165f31005f7acc0ce23453c2af6ac11ac05c2f7..bff8ba8d2060c416eb395547d341b169688f81d0 100644 (file)
@@ -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;
 }
index 35150aea769f46769e8a0ba219378c7e8269e768..49632ffcbc43b3eae4498070d32a5ef9a6c25e29 100644 (file)
@@ -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