forked from len0rd/rockbox
Added bad filename protection when user enters an fm radio preset filename. Fixes bugreport 5137.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9795 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
45406014d7
commit
ab90b1d55e
3 changed files with 54 additions and 5 deletions
|
|
@ -8501,3 +8501,17 @@
|
|||
*: "All tracks"
|
||||
</voice>
|
||||
</phrase>
|
||||
<phrase>
|
||||
id: LANG_INVALID_FILENAME
|
||||
desc: "invalid filename entered" error message
|
||||
user:
|
||||
<source>
|
||||
*: "Invalid Filename!"
|
||||
</source>
|
||||
<dest>
|
||||
*: "Invalid Filename!"
|
||||
</dest>
|
||||
<voice>
|
||||
*: "Invalid Filename"
|
||||
</voice>
|
||||
</phrase>
|
||||
|
|
@ -1223,13 +1223,47 @@ bool save_preset_list(void)
|
|||
{
|
||||
if(num_presets != 0)
|
||||
{
|
||||
bool bad_file_name = true;
|
||||
|
||||
if(!opendir(FMPRESET_PATH)) /* Check if there is preset folder */
|
||||
mkdir(FMPRESET_PATH, 0);
|
||||
|
||||
create_numbered_filename(filepreset, FMPRESET_PATH, "preset", ".fmr", 2);
|
||||
create_numbered_filename(filepreset,FMPRESET_PATH,"preset",".fmr",2);
|
||||
|
||||
if (!kbd_input(filepreset, sizeof(filepreset)))
|
||||
radio_save_presets();
|
||||
while(bad_file_name)
|
||||
{
|
||||
if(!kbd_input(filepreset, sizeof(filepreset)))
|
||||
{
|
||||
/* check the name: max MAX_FILENAME (20) chars */
|
||||
char* p2;
|
||||
char* p1;
|
||||
int len;
|
||||
p1 = strrchr(filepreset, '/');
|
||||
p2 = p1;
|
||||
while((p1) && (*p2) && (*p2 != '.'))
|
||||
p2++;
|
||||
len = (int)(p2-p1) - 1;
|
||||
if((!p1) || (len > MAX_FILENAME) || (len == 0))
|
||||
{
|
||||
/* no slash, too long or too short */
|
||||
gui_syncsplash(HZ,true,str(LANG_INVALID_FILENAME));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* add correct extension (easier to always write)
|
||||
at this point, p2 points to 0 or the extension dot */
|
||||
*p2 = '\0';
|
||||
strcat(filepreset,".fmr");
|
||||
bad_file_name = false;
|
||||
radio_save_presets();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* user aborted */
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
gui_syncsplash(HZ,true,str(LANG_FM_NO_PRESETS));
|
||||
|
|
|
|||
|
|
@ -1316,10 +1316,11 @@ void set_file(char* filename, char* setting, int maxlen)
|
|||
|
||||
len = strlen(fptr);
|
||||
ptr = fptr + len;
|
||||
while (*ptr != '.') {
|
||||
while ((*ptr != '.') && (ptr != fptr)) {
|
||||
extlen++;
|
||||
ptr--;
|
||||
}
|
||||
if(ptr == fptr) extlen = 0;
|
||||
|
||||
if (strncasecmp(ROCKBOX_DIR, filename ,strlen(ROCKBOX_DIR)) ||
|
||||
(len-extlen > maxlen))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue