validate global_settings.start_directory on startup

check for an ending slash and verify paths other than root
exist

Change-Id: I4e1b3d51d99e5f5b66bcc0d66866ae35a554f84d
This commit is contained in:
William Wilgus 2026-02-25 00:47:30 -05:00
parent 246bf4af75
commit 9a6e3799e1
3 changed files with 25 additions and 1 deletions

View file

@ -241,6 +241,7 @@ int main(void)
#endif /* #ifdef AUTOROCK */
global_status.last_volume_change = 0;
validate_start_directory_init();
/* no calls INIT_ATTR functions after this point anymore!
* see definition of INIT_ATTR in config.h */
CHART(">root_menu");

View file

@ -2018,4 +2018,27 @@ void clear_screen_buffer(bool update)
}
}
void validate_start_directory_init(void) /* INIT_ATTR */
{
char * const dirpath = global_settings.start_directory;
char *slash = strrchr(dirpath, PATH_SEPCH);
if (!slash)
{
path_append(dirpath, PATH_ROOTSTR, PA_SEP_HARD,
sizeof(global_settings.start_directory));
return; /* if this doesn't exist we have bigger issues */
}
else if(slash[1] != '\0') /* ending slash required */
{
path_append(dirpath, dirpath, PA_SEP_HARD,
sizeof(global_settings.start_directory));
}
if (slash != dirpath && !dir_exists(dirpath))
{
path_append(dirpath, PATH_ROOTSTR,
PA_SEP_HARD, sizeof(global_settings.start_directory));
}
}
#endif /* ndef __PCTOOL__ */

View file

@ -128,7 +128,7 @@ long default_event_handler_ex(long event, void (*callback)(void *), void *parame
long default_event_handler(long event);
bool list_stop_handler(void);
void car_adapter_mode_init(void) INIT_ATTR;
void validate_start_directory_init(void) INIT_ATTR;
/* Unicode byte order mark sequences and lengths */
#define BOM_UTF_8 "\xef\xbb\xbf"
#define BOM_UTF_8_SIZE 3