From: B Horn <b...@horn.uk>

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.ki...@oracle.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.11.0


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

Reply via email to