From mboxrd@z Thu Jan 1 00:00:00 1970 From: Heinrich Schuchardt Date: Sun, 31 Jan 2021 00:09:51 +0100 Subject: [PATCH 2/4] fs: fat: must not write directory '.' and '..' In-Reply-To: <20210130230953.307517-1-xypron.glpk@gmx.de> References: <20210130230953.307517-1-xypron.glpk@gmx.de> Message-ID: <20210130230953.307517-3-xypron.glpk@gmx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 --- 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