summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2014-02-25 09:52:07 +0100
committerThomas Martitz <kugel@rockbox.org>2014-02-25 09:52:07 +0100
commit731072de7acfbbeacd992eea1274bc8f35a42163 (patch)
tree5b57db8a3a4837553029fa1d922135eefcc4be9e
parent5fd8dd1321bd3513e0b03ef9474d88b2a8161c16 (diff)
downloadrockbox-731072d.tar.gz
rockbox-731072d.tar.bz2
rockbox-731072d.zip
application: Remove trailing slashes from the input in opendir().
This is needed for readdir() and dir_get_info() to work properly because they depend on hash/path matching. Change-Id: Ibd23def10eebabd76cdddac2739a5274159e88a9
-rw-r--r--firmware/common/rbpaths.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/firmware/common/rbpaths.c b/firmware/common/rbpaths.c
index 7632b70306..8cf92fab4a 100644
--- a/firmware/common/rbpaths.c
+++ b/firmware/common/rbpaths.c
@@ -341,10 +341,14 @@ DIR* app_opendir(const char *_name)
return NULL;
struct __dir *this = (struct __dir*)buf;
- /* definitely fits due to strlen() */
- strcpy(this->path, name);
-
- this->dir = opendir(name);
+ /* carefully remove any trailing slash from the input, so that
+ * hash/path matching in readdir() works properly */
+ while (name[name_len-1] == '/')
+ name_len -= 1;
+ /* strcpy cannot be used because of trailing slashes */
+ memcpy(this->path, name, name_len);
+ this->path[name_len] = 0;
+ this->dir = opendir(this->path);
if (!this->dir)
{