Skip to contentSkip to conversation

fs/ext2: fix the file not found error when symlink filesize == 60

PATCH Superseded Yi Zhao 1 participant 1 message Jan 7, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yi Zhao

author
#0 lore raw

PATCH 1/1 fs/ext2: fix the file not found error when symlink filesize == 60

We encountered a file not found error when the symlink filesize is equal to 60:

$ ls -l initrd
lrwxrwxrwx 1 root root 60 Jan  6 16:37 initrd -> secure-core-image-initramfs-5.10.2-yoctodev-standard.cpio.gz

When booting, we got the following error in grub:
error: file `/initrd' not found

The root cause is although the size of diro->inode.symlink is 60, it includes the trailing '\0'. So if the symlink filesize is exactly 60, it is also stored in a separate block.

---
 grub-core/fs/ext2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/fs/ext2.c +1 -1
index ac33bcd68..cb5058e8b 100644
@@ -732,7 +732,7 @@ grub_ext2_read_symlink (grub_fshelp_node_t node)
   /* If the filesize of the symlink is bigger than
      60 the symlink is stored in a separate block,
      otherwise it is stored in the inode.  */
-  if (grub_le_to_cpu32 (diro->inode.size) <= sizeof (diro->inode.symlink))
+  if (grub_le_to_cpu32 (diro->inode.size) < sizeof (diro->inode.symlink))
     grub_memcpy (symlink,
 		 diro->inode.symlink,
 		 grub_le_to_cpu32 (diro->inode.size));
Signature · 1 line
2.25.1