[prev in list] [next in list] [prev in thread] [next in thread] 

List:       grub-devel
Subject:    [PATCH v9 09/11] kern: check for NULL when closing devices and disks
From:       Oliver Steffen <osteffen () redhat ! com>
Date:       2023-05-26 11:35:50
Message-ID: 20230526113552.555635-10-osteffen () redhat ! com
[Download RAW message or body]

Add checks for NULL pointers to grub_device_close() and
grub_disk_close() to make these functions more robust.

Signed-off-by: Oliver Steffen <osteffen@redhat.com>
---
 grub-core/kern/device.c | 3 +++
 grub-core/kern/disk.c   | 4 ++++
 2 files changed, 7 insertions(+)

diff --git a/grub-core/kern/device.c b/grub-core/kern/device.c
index 92ce8a75e..670e213cf 100644
--- a/grub-core/kern/device.c
+++ b/grub-core/kern/device.c
@@ -71,6 +71,9 @@ grub_device_open (const char *name)
 grub_err_t
 grub_device_close (grub_device_t device)
 {
+  if (device == NULL)
+    return GRUB_ERR_NONE;
+
   if (device->disk)
     grub_disk_close (device->disk);
 
diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c
index eb0c7bb73..1eda58fe9 100644
--- a/grub-core/kern/disk.c
+++ b/grub-core/kern/disk.c
@@ -292,6 +292,10 @@ void
 grub_disk_close (grub_disk_t disk)
 {
   grub_partition_t part;
+
+  if (disk == NULL)
+    return;
+
   grub_dprintf ("disk", "Closing `%s'.\n", disk->name);
 
   if (disk->dev && disk->dev->disk_close)
-- 
2.40.1


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic