]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
kern: Check for NULL when closing devices and disks
authorOliver Steffen <osteffen@redhat.com>
Fri, 26 May 2023 11:35:50 +0000 (13:35 +0200)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 1 Jun 2023 09:45:00 +0000 (11:45 +0200)
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>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/kern/device.c
grub-core/kern/disk.c

index 92ce8a75e3a8341a7a4776048e40814fc91c678d..670e213cf3c11924be743e5346a4771bb08ce7a9 100644 (file)
@@ -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);
 
index eb0c7bb739aa341d57d63c2f6e8833591213c60d..1eda58fe9a1ceb0597200f395ed127cfd3050e90 100644 (file)
@@ -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)