1
0
Fork 0
forked from len0rd/rockbox

FS#13519: multivolume: Ensure absolute paths get drive designation

Change-Id: I8419af670ca101b11bba29d9fd577f21fa22fd42
This commit is contained in:
Dana Conrad 2024-12-05 01:54:01 +00:00 committed by Solomon Peachy
parent aeb4b6c34a
commit 7d3cc24dec
2 changed files with 36 additions and 5 deletions

View file

@ -27,6 +27,9 @@
#include "file_internal.h"
#include "debug.h"
// #define LOGF_ENABLE
#include "logf.h"
#ifdef HAVE_MULTIVOLUME
#include "storage.h"
@ -521,10 +524,36 @@ size_t path_append_ex(char *buf, const char *basepath, size_t basepath_max,
if (path_is_absolute(component)) /* starts with a '/' path separator */
{
/* 'component' is absolute; replace all */
basepath = component;
component = "";
basepath_max = -1u;
#if defined(HAVE_MULTIVOLUME)
const char *baseend;
/* our component doesn't appear to have a drive/volume */
if (path_strip_volume(component, &baseend, false) == ROOT_VOLUME)
{
/* find the basepath's drive/volume name, if it has one.
* ensure basepath is not NULL, that causes a crash on sim */
if (basepath != NULL && path_strip_volume(basepath, &baseend, false) != ROOT_VOLUME)
{
basepath_max = baseend - basepath;
/* strip leading separators from component */
while (*component == PATH_SEPCH)
component++;
} else {
/* component is absolute with no drive/volume, but basepath doesn't
* have a volume either... we must be on root volume */
basepath = component;
component = "";
basepath_max = -1u;
}
}
/* else component likely already has drive/volume name */
else
#endif
{
/* 'component' is absolute; replace all */
basepath = component;
component = "";
basepath_max = -1u;
}
}
/* if basepath is not null or empty, buffer contents are replaced,