summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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,
1234 return 0; 1234 return 0;
1235} 1235}
1236 1236
1237static 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
1237static int add_dir_entry(struct fat_dir* dir, 1246static 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 */