mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Ulrich Ölmann" <u.oelmann@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 1/2] fs: fix error path in __canonicalize_path()
Date: Mon, 16 Apr 2018 14:22:24 +0200	[thread overview]
Message-ID: <20180416122225.6302-1-u.oelmann@pengutronix.de> (raw)

Report failure in resolving links to the caller and only clean up memory then.

Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de>
---
 fs/fs.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 5135112c8b81..7c818eca024f 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -202,8 +202,11 @@ static char *__canonicalize_path(const char *_pathname, int level)
 			continue;
 
 		ret = readlink(outpath, link, PATH_MAX - 1);
-		if (ret < 0)
+		if (ret < 0) {
+			free(outpath);
+			outpath = ERR_PTR(ret);
 			goto out;
+		}
 
 		if (link[0] == '/') {
 			free(outpath);
@@ -218,14 +221,15 @@ static char *__canonicalize_path(const char *_pathname, int level)
 		if (IS_ERR(outpath))
 			goto out;
 	}
-out:
-	free(freep);
 
 	if (!*outpath) {
 		free(outpath);
 		outpath = xstrdup("/");
 	}
 
+out:
+	free(freep);
+
 	return outpath;
 }
 
-- 
2.16.3


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

             reply	other threads:[~2018-04-16 12:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-16 12:22 Ulrich Ölmann [this message]
2018-04-16 12:22 ` [PATCH 2/2] fs: remove shortcut in canonicalizing filenames Ulrich Ölmann

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=20180416122225.6302-1-u.oelmann@pengutronix.de \
    --to=u.oelmann@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