mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 4/4] fs: legacy: gracefully handle non existent files
Date: Tue, 11 Jun 2024 08:57:18 +0200	[thread overview]
Message-ID: <20240611065718.2899625-4-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240611065718.2899625-1-a.fatoum@pengutronix.de>

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@pengutronix.de>
---
 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




  parent reply	other threads:[~2024-06-11  6:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-11  6:57 [PATCH master 1/4] efi: hide EFI related symbols when !EFI Ahmad Fatoum
2024-06-11  6:57 ` [PATCH master 2/4] lib: wchar: guard against NULL in strdup_wchar Ahmad Fatoum
2024-06-11  6:57 ` [PATCH master 3/4] efi: payload: gracefully handle NULL parent image device path Ahmad Fatoum
2024-06-11  6:57 ` Ahmad Fatoum [this message]
2024-06-13  7:30 ` [PATCH master 1/4] efi: hide EFI related symbols when !EFI Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240611065718.2899625-4-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox