Index: firmware/drivers/fat.c =================================================================== --- firmware/drivers/fat.c (revision 13496) +++ firmware/drivers/fat.c (working copy) @@ -1172,13 +1172,44 @@ return 0; } - +static bool is_char_legal(char c) +{ + switch(c) + { + case 0x22: + case 0x2a: + case 0x2b: + case 0x2c: + case 0x2e: + case 0x3a: + case 0x3b: + case 0x3c: + case 0x3d: + case 0x3e: + case 0x3f: + case 0x5b: + case 0x5c: + case 0x5d: + case 0x7c: + return false; + default: + if(c <= 0x20) + return false; + } + return true; +} static int fat_checkname(const unsigned char* newname) { /* More sanity checks are probably needed */ if ( newname[strlen(newname) - 1] == '.' ) { return -1; } + while (*newname) + { + if (!is_char_legal(*newname)) + return -1; + newname++; + } return 0; } @@ -1346,35 +1377,19 @@ static unsigned char char2dos(unsigned char c, int* randomize) { - switch(c) + if (!is_char_legal(c)) { - case 0x22: - case 0x2a: - case 0x2b: - case 0x2c: - case 0x2e: - case 0x3a: - case 0x3b: - case 0x3c: - case 0x3d: - case 0x3e: - case 0x3f: - case 0x5b: - case 0x5c: - case 0x5d: - case 0x7c: + if(c <= 0x20) + c = 0; /* Illegal char, remove */ + else + { /* Illegal char, replace */ c = '_'; *randomize = 1; /* as per FAT spec */ - break; - - default: - if(c <= 0x20) - c = 0; /* Illegal char, remove */ - else - c = toupper(c); - break; + } } + else + c = toupper(c); return c; }