forked from len0rd/rockbox
[Bugfix] ft_assemble_path extra slashes, Volume unmound double free
Change-Id: Ie2e7702d8e252ce29af0b9dbd2e8d9e892b9ca18
This commit is contained in:
parent
19f21a2b3f
commit
52e22b253d
3 changed files with 56 additions and 30 deletions
|
@ -477,41 +477,46 @@ static void ft_apply_skin_file(char *buf, char *file, const int maxlen)
|
||||||
|
|
||||||
int ft_assemble_path(char *buf, size_t bufsz, const char* currdir, const char* filename)
|
int ft_assemble_path(char *buf, size_t bufsz, const char* currdir, const char* filename)
|
||||||
{
|
{
|
||||||
int len;
|
size_t len;
|
||||||
if (!filename)
|
if (!filename)
|
||||||
filename = "";
|
filename = "";
|
||||||
|
|
||||||
#ifdef HAVE_MULTIVOLUME
|
#ifdef HAVE_MULTIVOLUME
|
||||||
if (currdir && currdir[0] && currdir[1]) /* Not in / */
|
if (currdir && currdir[0] && currdir[1]) /* Not in / */
|
||||||
{
|
{
|
||||||
if (currdir[1] != VOL_START_TOK)
|
if (currdir[1] != VOL_START_TOK)
|
||||||
{
|
{
|
||||||
len = snprintf(buf, bufsz, "%s%s/%s", root_realpath(), currdir, filename);
|
len = path_append(buf, root_realpath(), currdir, bufsz);
|
||||||
|
if (len < bufsz)
|
||||||
|
len = path_append(buf, buf + len, filename, bufsz - len);
|
||||||
}
|
}
|
||||||
else
|
len = path_append(buf, currdir, filename, bufsz);
|
||||||
len = snprintf(buf, bufsz, "%s/%s", currdir, filename);
|
|
||||||
}
|
}
|
||||||
else /* In / */
|
else /* In / */
|
||||||
{
|
{
|
||||||
if (filename[0] != VOL_START_TOK)
|
if (filename[0] != VOL_START_TOK)
|
||||||
{
|
{
|
||||||
len = snprintf(buf, bufsz, "%s/%s",root_realpath(), filename);
|
len = path_append(buf, root_realpath(), filename, bufsz);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
len = snprintf(buf, bufsz, "/%s", filename);
|
len = path_append(buf, PATH_SEPSTR, filename, bufsz);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (currdir && currdir[0] && currdir[1]) /* Not in / */
|
if (currdir && currdir[0] && currdir[1]) /* Not in / */
|
||||||
{
|
{
|
||||||
len = snprintf(buf, bufsz, "%s%s/%s", root_realpath(), currdir, filename);
|
len = path_append(buf, root_realpath(), currdir, bufsz);
|
||||||
|
if(len < bufsz)
|
||||||
|
len = path_append(buf, buf + len, filename, bufsz - len);
|
||||||
}
|
}
|
||||||
else /* In / */
|
else /* In / */
|
||||||
{
|
{
|
||||||
len = snprintf(buf, bufsz, "%s/%s",root_realpath(), filename);
|
len = path_append(buf, root_realpath(), filename, bufsz);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if ((unsigned) len > bufsz)
|
|
||||||
|
if (len > bufsz)
|
||||||
splash(HZ, ID2P(LANG_PLAYLIST_DIRECTORY_ACCESS_ERROR));
|
splash(HZ, ID2P(LANG_PLAYLIST_DIRECTORY_ACCESS_ERROR));
|
||||||
return len;
|
return (int)len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_enter(struct tree_context* c)
|
int ft_enter(struct tree_context* c)
|
||||||
|
@ -528,7 +533,6 @@ int ft_enter(struct tree_context* c)
|
||||||
|
|
||||||
int file_attr = file->attr;
|
int file_attr = file->attr;
|
||||||
ft_assemble_path(buf, sizeof(buf), c->currdir, file->name);
|
ft_assemble_path(buf, sizeof(buf), c->currdir, file->name);
|
||||||
|
|
||||||
if (file_attr & ATTR_DIRECTORY) {
|
if (file_attr & ATTR_DIRECTORY) {
|
||||||
memcpy(c->currdir, buf, sizeof(c->currdir));
|
memcpy(c->currdir, buf, sizeof(c->currdir));
|
||||||
if ( c->dirlevel < MAX_DIR_LEVELS )
|
if ( c->dirlevel < MAX_DIR_LEVELS )
|
||||||
|
@ -815,16 +819,38 @@ int ft_exit(struct tree_context* c)
|
||||||
char buf[MAX_PATH];
|
char buf[MAX_PATH];
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
bool exit_func = false;
|
bool exit_func = false;
|
||||||
|
|
||||||
int i = strlen(c->currdir);
|
int i = strlen(c->currdir);
|
||||||
if (i>1) {
|
if (i>1) {
|
||||||
while (c->currdir[i-1]!='/')
|
while (c->currdir[i-1]!=PATH_SEPCH)
|
||||||
i--;
|
i--;
|
||||||
strcpy(buf,&c->currdir[i]);
|
strcpy(buf,&c->currdir[i]);
|
||||||
if (i==1)
|
if (i==1)
|
||||||
c->currdir[i]=0;
|
c->currdir[i]='\0';
|
||||||
else
|
else
|
||||||
c->currdir[i-1]=0;
|
c->currdir[i-1]='\0';
|
||||||
|
|
||||||
|
#ifdef HAVE_MULTIVOLUME /* un-redirect the realpath */
|
||||||
|
if ((unsigned)c->dirlevel<=2) /* only expect redirect two levels max */
|
||||||
|
{
|
||||||
|
char *currdir = c->currdir;
|
||||||
|
const char *root = root_realpath();
|
||||||
|
int len = i-1;
|
||||||
|
/* compare to the root path bail if they don't match except single '/' */
|
||||||
|
for (; len > 0 && *root != '\0' && *root == *currdir; len--)
|
||||||
|
{
|
||||||
|
root++;
|
||||||
|
currdir++;
|
||||||
|
}
|
||||||
|
if (*root == PATH_SEPCH) /* root may have trailing slash */
|
||||||
|
root++;
|
||||||
|
if (*root == '\0' &&
|
||||||
|
(len == 0 || (len == 1 && *currdir == PATH_SEPCH)))
|
||||||
|
{
|
||||||
|
strcpy(c->currdir, PATH_ROOTSTR);
|
||||||
|
c->dirlevel=1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (*c->dirfilter > NUM_FILTER_MODES && c->dirlevel < 1)
|
if (*c->dirfilter > NUM_FILTER_MODES && c->dirlevel < 1)
|
||||||
exit_func = true;
|
exit_func = true;
|
||||||
|
|
|
@ -74,7 +74,7 @@ static void unmount_item(int item)
|
||||||
if (!state)
|
if (!state)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (state & NSITEM_CONTENTS)
|
if (item == ROOT_CONTENTS_INDEX && state & NSITEM_CONTENTS)
|
||||||
{
|
{
|
||||||
fileobj_unmount(root_bindp);
|
fileobj_unmount(root_bindp);
|
||||||
root_bindp = NULL;
|
root_bindp = NULL;
|
||||||
|
@ -139,18 +139,19 @@ int root_mount_path(const char *path, unsigned int flags)
|
||||||
int root_state = NSITEM_MOUNTED | (flags & (NSITEM_HIDDEN|NSITEM_CONTENTS));
|
int root_state = NSITEM_MOUNTED | (flags & (NSITEM_HIDDEN|NSITEM_CONTENTS));
|
||||||
set_root_item_state(ROOT_CONTENTS_INDEX, root_state);
|
set_root_item_state(ROOT_CONTENTS_INDEX, root_state);
|
||||||
flags |= state; /* preserve the state of the mounted volume */
|
flags |= state; /* preserve the state of the mounted volume */
|
||||||
if (!folder)
|
|
||||||
{
|
|
||||||
folder = "";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/*if a folder has been enumerated don't mark the whole volume */
|
|
||||||
if (folder[0] != '\0' && folder[1] != '\0')
|
|
||||||
flags &= ~NSITEM_CONTENTS;
|
|
||||||
|
|
||||||
|
if (folder)
|
||||||
|
{
|
||||||
|
while (*folder == PATH_SEPCH)
|
||||||
|
folder++;
|
||||||
|
/*if a folder has been enumerated don't mark the whole volume */
|
||||||
|
if (folder[0] != '\0')
|
||||||
|
flags &= ~NSITEM_CONTENTS;
|
||||||
|
else
|
||||||
|
folder = NULL; /*Ensure separator is added by path_append */
|
||||||
}
|
}
|
||||||
snprintf(root_realpath_internal(), ROOT_MAX_REALPATH,"%s%s", volname, folder);
|
|
||||||
|
path_append(root_realpath_internal(), volname, folder, ROOT_MAX_REALPATH);
|
||||||
}
|
}
|
||||||
else if (state) /* error volume already mounted */
|
else if (state) /* error volume already mounted */
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
|
|
|
@ -139,10 +139,8 @@ static inline void fileop_onsync_internal(struct filestr_base *stream)
|
||||||
|
|
||||||
static inline void volume_onmount_internal(IF_MV_NONVOID(int volume))
|
static inline void volume_onmount_internal(IF_MV_NONVOID(int volume))
|
||||||
{
|
{
|
||||||
#if (defined(HAVE_MULTIVOLUME) || (defined(HAVE_MULTIBOOT) && !defined(BOOTLOADER)))
|
|
||||||
char path[VOL_MAX_LEN+2];
|
|
||||||
#endif
|
|
||||||
#if defined(HAVE_MULTIBOOT) && !defined(SIMULATOR) && !defined(BOOTLOADER)
|
#if defined(HAVE_MULTIBOOT) && !defined(SIMULATOR) && !defined(BOOTLOADER)
|
||||||
|
char path[VOL_MAX_LEN+2];
|
||||||
char rtpath[MAX_PATH / 2];
|
char rtpath[MAX_PATH / 2];
|
||||||
make_volume_root(volume, path);
|
make_volume_root(volume, path);
|
||||||
|
|
||||||
|
@ -185,6 +183,7 @@ standard_redirect:
|
||||||
root_mount_path(RB_ROOT_CONTENTS_DIR, NSITEM_CONTENTS);
|
root_mount_path(RB_ROOT_CONTENTS_DIR, NSITEM_CONTENTS);
|
||||||
}
|
}
|
||||||
#elif defined(HAVE_MULTIVOLUME)
|
#elif defined(HAVE_MULTIVOLUME)
|
||||||
|
char path[VOL_MAX_LEN+2];
|
||||||
make_volume_root(volume, path);
|
make_volume_root(volume, path);
|
||||||
root_mount_path(path, RB_ROOT_VOL_HIDDEN(volume) ? NSITEM_HIDDEN : 0);
|
root_mount_path(path, RB_ROOT_VOL_HIDDEN(volume) ? NSITEM_HIDDEN : 0);
|
||||||
if (volume == path_strip_volume(RB_ROOT_CONTENTS_DIR, NULL, false))
|
if (volume == path_strip_volume(RB_ROOT_CONTENTS_DIR, NULL, false))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue