summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2017-09-05 09:38:59 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2017-09-06 13:55:11 +0200
commiteed363f4479795a0d005dfd40d11a1936e62ab40 (patch)
tree39610051dc0fb03fedc0981b3093fca5ffff2d08
parentd01954ef973a883fe8d51c610c1f89dc5bbc9f1e (diff)
downloadbarebox-eed363f4479795a0d005dfd40d11a1936e62ab40.tar.gz
barebox-eed363f4479795a0d005dfd40d11a1936e62ab40.tar.xz
fs: avoid pathes with '//' in __canonicalize_path()
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@pengutronix.de>
-rw-r--r--fs/fs.c9
1 files 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;
}