]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Use _cleanup_ in shim
authorJan Janssen <medhefgo@web.de>
Thu, 13 Jan 2022 12:41:57 +0000 (13:41 +0100)
committerJan Janssen <medhefgo@web.de>
Thu, 13 Jan 2022 13:30:51 +0000 (14:30 +0100)
Also, better be safe than sorry and check the return value.

src/boot/efi/shim.c

index fd9c489478d2ba4bcbb531b5a30a2b35ee448b3d..fb4aecaee0217ada87254dc279fa4bf14770ca4b 100644 (file)
@@ -105,7 +105,6 @@ static EFIAPI EFI_STATUS security_policy_authentication (const EFI_SECURITY_PROT
         _cleanup_freepool_ EFI_DEVICE_PATH *dev_path = NULL;
         _cleanup_freepool_ CHAR16 *dev_path_str = NULL;
         EFI_HANDLE h;
-        EFI_FILE *root;
         _cleanup_freepool_ CHAR8 *file_buffer = NULL;
         UINTN file_size;
 
@@ -123,8 +122,10 @@ static EFIAPI EFI_STATUS security_policy_authentication (const EFI_SECURITY_PROT
         if (EFI_ERROR(status))
                 return status;
 
-        /* No need to check return value, this already happened in efi_main() */
-        root = LibOpenRoot(h);
+        _cleanup_(file_closep) EFI_FILE *root = LibOpenRoot(h);
+        if (!root)
+                return EFI_NOT_FOUND;
+
         dev_path_str = DevicePathToStr(dp);
         if (!dev_path_str)
                 return EFI_OUT_OF_RESOURCES;
@@ -132,7 +133,6 @@ static EFIAPI EFI_STATUS security_policy_authentication (const EFI_SECURITY_PROT
         status = file_read(root, dev_path_str, 0, 0, &file_buffer, &file_size);
         if (EFI_ERROR(status))
                 return status;
-        root->Close(root);
 
         if (shim_validate(file_buffer, file_size))
                 return EFI_SUCCESS;