[PATCH master 4/4] fs: legacy: gracefully handle non existent files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <a.fatoum@xxxxxxxxxxxxxx>
---
 fs/legacy.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/fs/legacy.c b/fs/legacy.c
index 7e886e7ae9a2..0d4d4d43ebac 100644
--- a/fs/legacy.c
+++ b/fs/legacy.c
@@ -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)
@@ -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;
@@ -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;
-- 
2.39.2





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux