Skip to content

Commit

Permalink
fs: legacy: gracefully handle non existent files
Browse files Browse the repository at this point in the history
The Semihosting file system API doesn't support listing files, so the
opendir callback returns NULL. This triggers crashes inside the legacy
dentry adapter code, so add some NULL checks to guard against this.

Signed-off-by: Ahmad Fatoum <[email protected]>
Link: https://lore.barebox.org/[email protected]
Signed-off-by: Sascha Hauer <[email protected]>
  • Loading branch information
a3f authored and saschahauer committed Jun 13, 2024
1 parent 5cf1c83 commit 2958ab6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion fs/legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ static int legacy_iterate(struct file *file, struct dir_context *ctx)
pathname = dpath(dentry, fsdev->vfsmount.mnt_root);

d = fsdev->driver->opendir(&fsdev->dev, pathname);
if (!d)
goto out;

while (1) {
dirent = fsdev->driver->readdir(&fsdev->dev, d);
if (!dirent)
Expand All @@ -38,7 +41,7 @@ static int legacy_iterate(struct file *file, struct dir_context *ctx)
}

fsdev->driver->closedir(&fsdev->dev, d);

out:
free(pathname);

return 0;
Expand All @@ -55,10 +58,14 @@ static struct dentry *legacy_lookup(struct inode *dir, struct dentry *dentry,
int ret;

pathname = dpath(dentry, fsdev->vfsmount.mnt_root);
if (!pathname)
return NULL;

ret = fsdev->driver->stat(&fsdev->dev, pathname, &s);
if (!ret) {
inode = legacy_get_inode(sb, dir, s.st_mode);
if (!inode)
return NULL;

inode->i_size = s.st_size;
inode->i_mode = s.st_mode;
Expand Down

0 comments on commit 2958ab6

Please sign in to comment.