mirror of
https://github.com/libretro/RetroArch
synced 2025-03-29 22:20:21 +00:00
Now path is also correctly sanitized. g_extern.basename of /path/to/file.zip#game.img is now /path/to/game
This commit is contained in:
parent
dd892712ad
commit
757f7d96c2
22
file_path.c
22
file_path.c
@ -426,7 +426,7 @@ void fill_pathname_base(char *out, const char *in_path, size_t size)
|
||||
|
||||
#ifdef HAVE_COMPRESSION
|
||||
const char *ptr_bak = ptr;
|
||||
ptr = strchr(ptr,'#');
|
||||
ptr = strchr(ptr_bak,'#');
|
||||
if (ptr)
|
||||
ptr++;
|
||||
else
|
||||
@ -466,7 +466,16 @@ void path_basedir(char *path)
|
||||
if (strlen(path) < 2)
|
||||
return;
|
||||
|
||||
char *last = find_last_slash(path);
|
||||
char *last;
|
||||
|
||||
#ifdef HAVE_COMPRESSION
|
||||
/* We want to find the directory with the zipfile in basedir. */
|
||||
last = strchr(path,'#');
|
||||
if (last)
|
||||
*last = '\0';
|
||||
#endif
|
||||
|
||||
last = find_last_slash(path);
|
||||
|
||||
if (last)
|
||||
last[1] = '\0';
|
||||
@ -486,6 +495,15 @@ const char *path_basename(const char *path)
|
||||
{
|
||||
const char *last = find_last_slash(path);
|
||||
|
||||
/* We cut either at the last hash or the last slash; whichever comes last */
|
||||
#ifdef HAVE_COMPRESSION
|
||||
const char *last_hash = strchr(path,'#');
|
||||
if (last_hash > last)
|
||||
{
|
||||
return last_hash + 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (last)
|
||||
return last + 1;
|
||||
return path;
|
||||
|
25
retroarch.c
25
retroarch.c
@ -1022,7 +1022,30 @@ static void set_basename(const char *path)
|
||||
char *dst = NULL;
|
||||
|
||||
strlcpy(g_extern.fullpath, path, sizeof(g_extern.fullpath));
|
||||
fill_pathname_base(g_extern.basename, path, sizeof(g_extern.basename));
|
||||
strlcpy(g_extern.basename, path, sizeof(g_extern.basename));
|
||||
/* Removing extension is a bit tricky for compressed files.
|
||||
* Basename means:
|
||||
* /file/to/path/game.extension should be:
|
||||
* /file/to/path/game
|
||||
*
|
||||
* Two things to consider here are: /file/to/path/ is expected
|
||||
* to be a directory and "game" is a single file. This is used for
|
||||
* states and srm default paths
|
||||
*
|
||||
* For compressed files we have:
|
||||
*
|
||||
* /file/to/path/comp.7z#game.extension and
|
||||
* /file/to/path/comp.7z#folder/game.extension
|
||||
*
|
||||
* The choice I take here is:
|
||||
* /file/to/path/game as basename. We might end up in a writable dir then
|
||||
* and the name of srm and states are meaningful.
|
||||
*
|
||||
*/
|
||||
#ifdef HAVE_COMPRESSION
|
||||
path_basedir(g_extern.basename);
|
||||
fill_pathname_dir(g_extern.basename,path,"",sizeof(g_extern.basename));
|
||||
#endif
|
||||
|
||||
if ((dst = strrchr(g_extern.basename, '.')))
|
||||
*dst = '\0';
|
||||
|
Loading…
x
Reference in New Issue
Block a user