[PATCH 1/2] fs: avoid pathes with '//' in __canonicalize_path()

Sascha Hauer s.hauer at pengutronix.de
Tue Sep 5 01:00:20 PDT 2017


In __canonicalize_path pathes beginning with '//' can occur. This
is normally not a problem since normalize_path() will clean this
up, but it means we cannot call get_fsdevice_by_path() on these
pathes in this function, as needed in the next patch.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 fs/fs.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index c9226f9ba6..a5efdd1423 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -158,8 +158,8 @@ static char *__canonicalize_path(const char *_pathname, int level)
 
 	path = freep = xstrdup(_pathname);
 
-	if (*path == '/')
-		outpath = xstrdup("/");
+	if (*path == '/' || !strcmp(cwd, "/"))
+		outpath = xstrdup("");
 	else
 		outpath = __canonicalize_path(cwd, level + 1);
 
@@ -212,6 +212,11 @@ static char *__canonicalize_path(const char *_pathname, int level)
 out:
 	free(freep);
 
+	if (!*outpath) {
+		free(outpath);
+		outpath = xstrdup("/");
+	}
+
 	return outpath;
 }
 
-- 
2.11.0




More information about the barebox mailing list