]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
fs/archelp: If path given to grub_archelp_dir() is not a directory return error
authorGlenn Washburn <development@efficientek.com>
Mon, 14 Aug 2023 06:03:41 +0000 (01:03 -0500)
committerDaniel Kiper <daniel.kiper@oracle.com>
Mon, 14 Aug 2023 16:07:24 +0000 (18:07 +0200)
Specifically, return GRUB_ERR_BAD_FILE_TYPE because this is what is
expected by the ls command when it is given a path to a non-directory.
This fixes a bug where calling ls with a list of non-directory paths
outputs a blank line for each such argument.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/fs/archelp.c

index 998de88b865c774161727e15a4453b7b4968aa77..c1dcc62858a9094d782b21647cd70d0ad814d6ca 100644 (file)
@@ -180,6 +180,14 @@ grub_archelp_dir (struct grub_archelp_data *data,
          if (p)
            *p = 0;
 
+         if ((*n == 0) && ((mode & GRUB_ARCHELP_ATTR_TYPE)
+                           != GRUB_ARCHELP_ATTR_DIR))
+           {
+             grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("not a directory"));
+             grub_free (name);
+             goto fail;
+           }
+
          if (((!prev) || (grub_strcmp (prev, name) != 0)) && *n != 0)
            {
              struct grub_dirhook_info info;