Skip to contentSkip to conversation

archelp: If path given to grub_archelp_dir is not a directory return error

PATCH In review Glenn Washburn 2 participants 2 messages Aug 14, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 archelp: If path given to grub_archelp_dir is not a directory return error

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.

---
 grub-core/fs/archelp.c | 8 ++++++++
 1 file changed, 8 insertions(+)
grub-core/fs/archelp.c +8 -0
index 998de88b865c..c1dcc62858a9 100644
@@ -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;
Signature · 7 lines
2.34.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Glenn Washburn

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.

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel