[PATCH 2/4] fs: fat: must not write directory '.' and '..'

Heinrich Schuchardt xypron.glpk at gmx.de
Sun Jan 31 00:09:51 CET 2021


Directories or files called '.' or '..' cannot be created or written to
in any directory. Move the test to normalize_longname() to check this
early.

Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
---
 fs/fat/fat_write.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index a9b9fa5d68..7bd7463464 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -1260,6 +1260,9 @@ static int normalize_longname(char *l_filename, const char *filename)
 {
 	const char *p, illegal[] = "<>:\"/\\|?*";

+	if (!strcmp(filename, ".") || !strcmp(filename, ".."))
+		return -1;
+
 	if (strlen(filename) >= VFAT_MAXLEN_BYTES)
 		return -1;

@@ -1348,15 +1351,6 @@ int file_fat_write_at(const char *filename, loff_t pos, void *buffer,
 		char shortname[SHORT_NAME_SIZE];
 		int ndent;

-		if (itr->is_root) {
-			/* root dir cannot have "." or ".." */
-			if (!strcmp(l_filename, ".") ||
-			    !strcmp(l_filename, "..")) {
-				ret = -EINVAL;
-				goto exit;
-			}
-		}
-
 		if (pos) {
 			/* No hole allowed */
 			ret = -EINVAL;
--
2.29.2



More information about the U-Boot mailing list