diff options
author | Jonas Häggqvist <rasher@rasher.dk> | 2005-09-07 01:35:15 +0000 |
---|---|---|
committer | Jonas Häggqvist <rasher@rasher.dk> | 2005-09-07 01:35:15 +0000 |
commit | 98143f52914a828f1de54abab6c6918a4dece979 (patch) | |
tree | c682d0870aaac700ef89a07f872082c477fc5cb3 /firmware | |
parent | 0dea3efd2f03b882ba6ca7e0cbac9b6994736a7c (diff) | |
download | rockbox-98143f52914a828f1de54abab6c6918a4dece979.tar.gz rockbox-98143f52914a828f1de54abab6c6918a4dece979.zip |
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')
-rw-r--r-- | firmware/drivers/fat.c | 22 |
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, | |||
1234 | return 0; | 1234 | return 0; |
1235 | } | 1235 | } |
1236 | 1236 | ||
1237 | static int fat_checkname(const unsigned char* newname) | ||
1238 | { | ||
1239 | /* More sanity checks are probably needed */ | ||
1240 | if ( newname[strlen(newname) - 1] == '.' ) { | ||
1241 | return -1; | ||
1242 | } | ||
1243 | return 0; | ||
1244 | } | ||
1245 | |||
1237 | static int add_dir_entry(struct fat_dir* dir, | 1246 | static int add_dir_entry(struct fat_dir* dir, |
1238 | struct fat_file* file, | 1247 | struct fat_file* file, |
1239 | const char* name, | 1248 | const char* name, |
@@ -1256,6 +1265,15 @@ static int add_dir_entry(struct fat_dir* dir, | |||
1256 | LDEBUGF( "add_dir_entry(%s,%lx)\n", | 1265 | LDEBUGF( "add_dir_entry(%s,%lx)\n", |
1257 | name, file->firstcluster); | 1266 | name, file->firstcluster); |
1258 | 1267 | ||
1268 | /* Don't check dotdirs name for validity */ | ||
1269 | if (dotdir == false) { | ||
1270 | rc = fat_checkname(name); | ||
1271 | if (rc < 0) { | ||
1272 | /* filename is invalid */ | ||
1273 | return rc * 10 - 1; | ||
1274 | } | ||
1275 | } | ||
1276 | |||
1259 | #ifdef HAVE_MULTIVOLUME | 1277 | #ifdef HAVE_MULTIVOLUME |
1260 | file->volume = dir->file.volume; /* inherit the volume, to make sure */ | 1278 | file->volume = dir->file.volume; /* inherit the volume, to make sure */ |
1261 | #endif | 1279 | #endif |
@@ -1282,7 +1300,7 @@ static int add_dir_entry(struct fat_dir* dir, | |||
1282 | 1300 | ||
1283 | rc = fat_seek(&dir->file, 0); | 1301 | rc = fat_seek(&dir->file, 0); |
1284 | if (rc < 0) | 1302 | if (rc < 0) |
1285 | return rc * 10 - 1; | 1303 | return rc * 10 - 2; |
1286 | 1304 | ||
1287 | /* step 1: search for free entries and check for duplicate shortname */ | 1305 | /* step 1: search for free entries and check for duplicate shortname */ |
1288 | for (sector = 0; !done; sector++) | 1306 | for (sector = 0; !done; sector++) |
@@ -1293,7 +1311,7 @@ static int add_dir_entry(struct fat_dir* dir, | |||
1293 | if (rc < 0) { | 1311 | if (rc < 0) { |
1294 | DEBUGF( "add_dir_entry() - Couldn't read dir" | 1312 | DEBUGF( "add_dir_entry() - Couldn't read dir" |
1295 | " (error code %d)\n", rc); | 1313 | " (error code %d)\n", rc); |
1296 | return rc * 10 - 2; | 1314 | return rc * 10 - 3; |
1297 | } | 1315 | } |
1298 | 1316 | ||
1299 | if (rc == 0) { /* current end of dir reached */ | 1317 | if (rc == 0) { /* current end of dir reached */ |