]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
commands/ls: Fix NULL dereference
authorB Horn <b@horn.uk>
Sun, 12 May 2024 10:08:23 +0000 (11:08 +0100)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 13 Feb 2025 14:45:55 +0000 (15:45 +0100)
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>
grub-core/commands/ls.c

index 6a1c7f5d362673d79c187ce92175ee268cecee6a..f660946a24e481eb2e28777409614985d6996384 100644 (file)
@@ -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;