grub2/0352-cmd-search-Fix-a-possible-NULL-ptr-dereference.patch
Nicolas Frayer 0e73191379 cmd/search: Fix a possible NULL ptr dereference
Resolves: #RHEL-61263
Signed-off-by: Nicolas Frayer <nfrayer@redhat.com>
2024-10-17 12:06:22 +02:00

60 lines
2.3 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Nicolas Frayer <nfrayer@redhat.com>
Date: Wed, 16 Oct 2024 15:50:32 +0200
Subject: [PATCH] cmd/search: Fix a possible NULL ptr dereference
When querying about a partition UUID, we're not checking
for get_device_uuid() return value, which can possibly
result in dereferencing a NULL pointer.
Signed-off-by: Nicolas Frayer <nfrayer@redhat.com>
Co-authored-by: Chuong Tran <anhchuong89@gmail.com>
---
grub-core/commands/search.c | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/grub-core/commands/search.c b/grub-core/commands/search.c
index c052cb098c36..ab0122704c34 100644
--- a/grub-core/commands/search.c
+++ b/grub-core/commands/search.c
@@ -211,24 +211,26 @@ iterate_device (const char *name, void *data)
struct uuid_context uuid_ctx;
int ret = 0;
- get_device_uuid(name, &quid_name);
- if (!grub_strcmp(quid_name, ctx->key))
+ if (get_device_uuid(name, &quid_name))
{
- uuid_ctx.name = name;
- uuid_ctx.uuid = quid_name;
+ if (!grub_strcmp(quid_name, ctx->key))
+ {
+ uuid_ctx.name = name;
+ uuid_ctx.uuid = quid_name;
- ret = grub_device_iterate (check_for_duplicate, &uuid_ctx);
+ ret = grub_device_iterate (check_for_duplicate, &uuid_ctx);
- if (ret)
- {
- grub_printf("Duplicated media UUID found, rebooting ...\n");
- grub_sleep(10);
- grub_reboot();
- }
- }
+ if (ret)
+ {
+ grub_printf("Duplicated media UUID found, rebooting ...\n");
+ grub_sleep(10);
+ grub_reboot();
+ }
+ }
- if (quid_name) grub_free (quid_name);
+ if (quid_name) grub_free (quid_name);
+ }
}
}
}