From 98143f52914a828f1de54abab6c6918a4dece979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20H=C3=A4ggqvist?= Date: Wed, 7 Sep 2005 01:35:15 +0000 Subject: Adds a filename sanity check to add_dir_entry that at the moment only checks for names ending in a period, but can easily be extended. Changes the error codes for add_dir_entry. Fixes bug #782248. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7487 a1c6a512-1295-4272-9138-f99709370657 --- firmware/drivers/fat.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'firmware/drivers') diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index 7bb2645506..e3e05f8523 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c @@ -1234,6 +1234,15 @@ static int write_long_name(struct fat_file* file, return 0; } +static int fat_checkname(const unsigned char* newname) +{ + /* More sanity checks are probably needed */ + if ( newname[strlen(newname) - 1] == '.' ) { + return -1; + } + return 0; +} + static int add_dir_entry(struct fat_dir* dir, struct fat_file* file, const char* name, @@ -1256,6 +1265,15 @@ static int add_dir_entry(struct fat_dir* dir, LDEBUGF( "add_dir_entry(%s,%lx)\n", name, file->firstcluster); + /* Don't check dotdirs name for validity */ + if (dotdir == false) { + rc = fat_checkname(name); + if (rc < 0) { + /* filename is invalid */ + return rc * 10 - 1; + } + } + #ifdef HAVE_MULTIVOLUME file->volume = dir->file.volume; /* inherit the volume, to make sure */ #endif @@ -1282,7 +1300,7 @@ static int add_dir_entry(struct fat_dir* dir, rc = fat_seek(&dir->file, 0); if (rc < 0) - return rc * 10 - 1; + return rc * 10 - 2; /* step 1: search for free entries and check for duplicate shortname */ for (sector = 0; !done; sector++) @@ -1293,7 +1311,7 @@ static int add_dir_entry(struct fat_dir* dir, if (rc < 0) { DEBUGF( "add_dir_entry() - Couldn't read dir" " (error code %d)\n", rc); - return rc * 10 - 2; + return rc * 10 - 3; } if (rc == 0) { /* current end of dir reached */ -- cgit v1.2.3