1
0
Fork 0
forked from len0rd/rockbox

settings set_file() cleanup unused maxlen and check for file exist

maxlen is set to MAX_FILENAME by all callers so lets just make that part of the deal
check the file exists before we set it

Change-Id: I3074f3164fcd4b8873b69612d5c1a51a39de4baf
This commit is contained in:
William Wilgus 2025-01-24 00:20:45 -05:00
parent 14898bc19e
commit bdf89bf4b0
4 changed files with 23 additions and 20 deletions

View file

@ -1284,8 +1284,9 @@ bool set_option(const char* string, const void* variable, enum optiontype type,
* Takes filename, removes the directory and the extension,
* and then copies the basename into setting, unless the basename exceeds maxlen
**/
void set_file(const char* filename, char* setting, const int maxlen)
void set_file(const char* filename, char* setting)
{
const int maxlen = MAX_FILENAME;
const char* fptr = strrchr(filename,'/');
const char* extptr;
int len;
@ -1305,9 +1306,12 @@ void set_file(const char* filename, char* setting, const int maxlen)
len = strlen(fptr) - extlen + 1;
/* error if filename isn't in ROCKBOX_DIR */
if (len > maxlen)
/* error later if filename isn't in ROCKBOX_DIR */
if (len > maxlen || !file_exists(filename))
{
DEBUGF("%s Error %s\n", __func__, filename);
return;
}
strmemccpy(setting, fptr, len);
settings_save();