barebox currently crashes when an empty path is passed to open(). This can be provoked with doing a 'nfs foo ""' on the command line. This series fixes the issue. Sascha Hauer (3): fs: check for empty name in getname() fs: check for valid name in filename_lookup() fs: check getname() return value in open() fs/fs.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) -- 2.29.2 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox
getname() should return an error for an empty path. While at it, change getname() to return an error pointer. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> --- fs/fs.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/fs.c b/fs/fs.c index 6de5a3b59e..09fccf9c28 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -1866,14 +1866,17 @@ static struct filename *getname(const char *filename) { struct filename *result; + if (!*filename) + return ERR_PTR(-ENOENT); + result = malloc(sizeof(*result)); if (!result) - return NULL; + return ERR_PTR(-ENOMEM); result->name = strdup(filename); if (!result->name) { free(result); - return NULL; + return ERR_PTR(-ENOMEM); } result->refcnt = 1; -- 2.29.2 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox
The getname() return value is passed to filename_lookup() without checking the return value, so this must be done in filename_lookup(). Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> --- fs/fs.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/fs.c b/fs/fs.c index 09fccf9c28..2eaf7eaa37 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -2189,6 +2189,9 @@ static int filename_lookup(int dfd, struct filename *name, unsigned flags, struct nameidata nd; const char *s; + if (IS_ERR(name)) + return PTR_ERR(name); + set_nameidata(&nd, dfd, name); s = path_init(&nd, flags); -- 2.29.2 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox
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