mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: Neeraj Pal <neerajpal09@gmail.com>
Subject: [PATCH 3/3] fs: check getname() return value in open()
Date: Fri,  7 May 2021 12:56:11 +0200	[thread overview]
Message-ID: <20210507105611.17017-4-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20210507105611.17017-1-s.hauer@pengutronix.de>

getname() can return an error when for example the input path is an
empty string. Check the getname() return value in open() before
further using it.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/fs.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/fs.c b/fs/fs.c
index 2eaf7eaa37..f4baba81e7 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2368,8 +2368,14 @@ int open(const char *pathname, int flags, ...)
 	struct dentry *dentry = NULL;
 	struct nameidata nd;
 	const char *s;
+	struct filename *filename;
+
+	filename = getname(pathname);
+	if (IS_ERR(filename))
+		return PTR_ERR(filename);
+
+	set_nameidata(&nd, AT_FDCWD, filename);
 
-	set_nameidata(&nd, AT_FDCWD, getname(pathname));
 	s = path_init(&nd, LOOKUP_FOLLOW);
 
 	while (1) {
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


      parent reply	other threads:[~2021-05-07 10:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-07 10:56 [PATCH 0/3] Fix opening empty path Sascha Hauer
2021-05-07 10:56 ` [PATCH 1/3] fs: check for empty name in getname() Sascha Hauer
2021-05-07 10:56 ` [PATCH 2/3] fs: check for valid name in filename_lookup() Sascha Hauer
2021-05-07 10:56 ` Sascha Hauer [this message]

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=20210507105611.17017-4-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=neerajpal09@gmail.com \
    /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