mirror of
https://github.com/libretro/RetroArch
synced 2025-04-01 04:20:27 +00:00
sanitize autoconfig filenames before saving
This commit is contained in:
parent
bd586e6d2d
commit
bc2d6d02af
@ -50,6 +50,12 @@
|
|||||||
|
|
||||||
#include "tasks/tasks_internal.h"
|
#include "tasks/tasks_internal.h"
|
||||||
|
|
||||||
|
static const char* invalid_filename_chars[] = {
|
||||||
|
/* https://support.microsoft.com/en-us/help/905231/information-about-the-characters-that-you-cannot-use-in-site-names--fo */
|
||||||
|
"~", "#", "%", "&", "*", "{", "}", "\\", ":", "[", "]", "?", "/", "|", "\'", "\"",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
/* All config related settings go here. */
|
/* All config related settings go here. */
|
||||||
|
|
||||||
struct config_bool_setting
|
struct config_bool_setting
|
||||||
@ -3443,6 +3449,7 @@ bool config_save_autoconf_profile(const char *path, unsigned user)
|
|||||||
unsigned i;
|
unsigned i;
|
||||||
char *buf = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
char *buf = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||||
char *autoconf_file = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
char *autoconf_file = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||||
|
char *path_new = NULL;
|
||||||
size_t path_size = PATH_MAX_LENGTH * sizeof(char);
|
size_t path_size = PATH_MAX_LENGTH * sizeof(char);
|
||||||
int32_t pid_user = 0;
|
int32_t pid_user = 0;
|
||||||
int32_t vid_user = 0;
|
int32_t vid_user = 0;
|
||||||
@ -3454,6 +3461,26 @@ bool config_save_autoconf_profile(const char *path, unsigned user)
|
|||||||
|
|
||||||
buf[0] = autoconf_file[0] = '\0';
|
buf[0] = autoconf_file[0] = '\0';
|
||||||
|
|
||||||
|
if (string_is_empty(path))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
path_new = strdup(path);
|
||||||
|
|
||||||
|
for (i = 0; invalid_filename_chars[i]; i++)
|
||||||
|
{
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
char *tmp = strstr(path_new, invalid_filename_chars[i]);
|
||||||
|
|
||||||
|
if (tmp)
|
||||||
|
*tmp = '_';
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
path = path_new;
|
||||||
|
|
||||||
fill_pathname_join(buf, autoconf_dir, joypad_ident, path_size);
|
fill_pathname_join(buf, autoconf_dir, joypad_ident, path_size);
|
||||||
|
|
||||||
if(path_is_directory(buf))
|
if(path_is_directory(buf))
|
||||||
@ -3479,7 +3506,7 @@ bool config_save_autoconf_profile(const char *path, unsigned user)
|
|||||||
path_size);
|
path_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
conf = config_file_new(autoconf_file);
|
conf = config_file_new(autoconf_file);
|
||||||
|
|
||||||
if (!conf)
|
if (!conf)
|
||||||
{
|
{
|
||||||
@ -3515,11 +3542,15 @@ bool config_save_autoconf_profile(const char *path, unsigned user)
|
|||||||
config_file_free(conf);
|
config_file_free(conf);
|
||||||
free(buf);
|
free(buf);
|
||||||
free(autoconf_file);
|
free(autoconf_file);
|
||||||
|
if (path_new)
|
||||||
|
free(path_new);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
free(buf);
|
free(buf);
|
||||||
free(autoconf_file);
|
free(autoconf_file);
|
||||||
|
if (path_new)
|
||||||
|
free(path_new);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user