Skip to content

Commit 2958ab6

Browse files
a3fsaschahauer
authored andcommitted
fs: legacy: gracefully handle non existent files
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]>
1 parent 5cf1c83 commit 2958ab6

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

fs/legacy.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ static int legacy_iterate(struct file *file, struct dir_context *ctx)
2929
pathname = dpath(dentry, fsdev->vfsmount.mnt_root);
3030

3131
d = fsdev->driver->opendir(&fsdev->dev, pathname);
32+
if (!d)
33+
goto out;
34+
3235
while (1) {
3336
dirent = fsdev->driver->readdir(&fsdev->dev, d);
3437
if (!dirent)
@@ -38,7 +41,7 @@ static int legacy_iterate(struct file *file, struct dir_context *ctx)
3841
}
3942

4043
fsdev->driver->closedir(&fsdev->dev, d);
41-
44+
out:
4245
free(pathname);
4346

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

5760
pathname = dpath(dentry, fsdev->vfsmount.mnt_root);
61+
if (!pathname)
62+
return NULL;
5863

5964
ret = fsdev->driver->stat(&fsdev->dev, pathname, &s);
6065
if (!ret) {
6166
inode = legacy_get_inode(sb, dir, s.st_mode);
67+
if (!inode)
68+
return NULL;
6269

6370
inode->i_size = s.st_size;
6471
inode->i_mode = s.st_mode;

0 commit comments

Comments
 (0)