[PATCH 1/3] fs: check for empty name in getname()

Sascha Hauer s.hauer at pengutronix.de
Fri May 7 03:56:09 PDT 2021


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 at 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




More information about the barebox mailing list