12345678910111213141516171819202122232425262728293031323334353637 |
- From 322d82364cc0db30b1ae4fc0adfdf7a43adc91ef Mon Sep 17 00:00:00 2001
- From: B Horn <b@horn.uk>
- Date: Sun, 12 May 2024 11:08:23 +0100
- Subject: [PATCH] commands/ls: Fix NULL dereference
- The grub_strrchr() may return NULL when the dirname do not contain "/".
- This can happen on broken filesystems.
- Reported-by: B Horn <b@horn.uk>
- Signed-off-by: B Horn <b@horn.uk>
- Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
- Upstream: 0bf56bce47489c059e50e61a3db7f682d8c44b56
- Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
- ---
- grub-core/commands/ls.c | 6 +++++-
- 1 file changed, 5 insertions(+), 1 deletion(-)
- diff --git a/grub-core/commands/ls.c b/grub-core/commands/ls.c
- index 6a1c7f5d3..f660946a2 100644
- --- a/grub-core/commands/ls.c
- +++ b/grub-core/commands/ls.c
- @@ -241,7 +241,11 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
-
- grub_file_close (file);
-
- - p = grub_strrchr (dirname, '/') + 1;
- + p = grub_strrchr (dirname, '/');
- + if (p == NULL)
- + goto fail;
- + ++p;
- +
- ctx.dirname = grub_strndup (dirname, p - dirname);
- if (ctx.dirname == NULL)
- goto fail;
- --
- 2.50.1
|