Skip to contentSkip to conversation

commands/ls: Send correct dirname to print funcions

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

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 commands/ls: Send correct dirname to print funcions

For each non-directory path argument to the ls command, the full path was being sent to the print functions, instead of the dirname. The long output print function expected dirname to be the directory containing the file and so could not open the file to get the file size because the generated path was incorrect. This caused the output to be a blank line.

---
 grub-core/commands/ls.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
grub-core/commands/ls.c +3 -3
index 8e98c73ccf7b..c746eae0c7e7 100644
@@ -242,8 +242,8 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
 	  grub_file_close (file);
 
 	  p = grub_strrchr (dirname, '/') + 1;
-	  dirname = grub_strndup (dirname, p - dirname);
-	  if (! dirname)
+	  ctx.dirname = grub_strndup (dirname, p - dirname);
+	  if (ctx.dirname == NULL)
 	    goto fail;
 
 	  all = 1;
@@ -253,7 +253,7 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
 	  else
 	    print_files (p, &info, &ctx);
 
-	  grub_free (dirname);
+	  grub_free (ctx.dirname);
 	}
 
       if (grub_errno == GRUB_ERR_NONE)
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 7 lines · Glenn Washburn

For each non-directory path argument to the ls command, the full path was being sent to the print functions, instead of the dirname. The long output print function expected dirname to be the directory containing the file and so could not open the file to get the file size because the generated path was incorrect. This caused the output to be a blank line.

Daniel

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