summaryrefslogtreecommitdiff
path: root/firmware/drivers
diff options
context:
space:
mode:
authorJonas Häggqvist <rasher@rasher.dk>2005-09-07 01:35:15 +0000
committerJonas Häggqvist <rasher@rasher.dk>2005-09-07 01:35:15 +0000
commit98143f52914a828f1de54abab6c6918a4dece979 (patch)
treec682d0870aaac700ef89a07f872082c477fc5cb3 /firmware/drivers
parent0dea3efd2f03b882ba6ca7e0cbac9b6994736a7c (diff)
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
Diffstat (limited to 'firmware/drivers')
-rw-r--r--firmware/drivers/fat.c22
1 files changed, 20 insertions, 2 deletions
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 */