Workaround the brokenness of realpath() a bit more.
At least on android it blindly writes to the end of the buffer passed to it assuming it's sufficiently. It wasn't in our case, resulting in a buffer overflow (and breakage). This should fix strange problems relating to database initialization on application targets. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29147 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
3a1bc3cfdd
commit
b703d251be
1 changed files with 14 additions and 6 deletions
|
@ -4226,8 +4226,17 @@ static bool add_search_root(const char *name)
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
struct search_roots_ll *this, *prev = NULL;
|
struct search_roots_ll *this, *prev = NULL;
|
||||||
char target[MAX_PATH];
|
char target[MAX_PATH];
|
||||||
char _abs_target[MAX_PATH];
|
/* Okay, realpath() is almost completely broken on android
|
||||||
char * abs_target;
|
*
|
||||||
|
* It doesn't accept NULL for resolved_name to dynamically allocate
|
||||||
|
* the resulting path; and it assumes resolved_name to be PATH_MAX
|
||||||
|
* (actually MAXPATHLEN, but it's the same [as of 2.3]) long
|
||||||
|
* and blindly writes to the end if it
|
||||||
|
*
|
||||||
|
* therefore use sufficiently large static storage here
|
||||||
|
* Note that PATH_MAX != MAX_PATH
|
||||||
|
**/
|
||||||
|
static char abs_target[PATH_MAX];
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
|
|
||||||
len = readlink(name, target, sizeof(target));
|
len = readlink(name, target, sizeof(target));
|
||||||
|
@ -4235,9 +4244,7 @@ static bool add_search_root(const char *name)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
target[len] = '\0';
|
target[len] = '\0';
|
||||||
/* realpath(target, NULL) doesn't work on android ... */
|
if (realpath(target, abs_target) == NULL)
|
||||||
abs_target = realpath(target, _abs_target);
|
|
||||||
if (abs_target == NULL)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for(this = &roots_ll; this; prev = this, this = this->next)
|
for(this = &roots_ll; this; prev = this, this = this->next)
|
||||||
|
@ -4258,6 +4265,7 @@ static bool add_search_root(const char *name)
|
||||||
logf("Error at adding a search root: %s", this ? "path too long":"OOM");
|
logf("Error at adding a search root: %s", this ? "path too long":"OOM");
|
||||||
free(this);
|
free(this);
|
||||||
prev->next = NULL;
|
prev->next = NULL;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
this->path = ((char*)this) + sizeof(struct search_roots_ll);
|
this->path = ((char*)this) + sizeof(struct search_roots_ll);
|
||||||
strcpy((char*)this->path, abs_target); /* ok to cast const away here */
|
strcpy((char*)this->path, abs_target); /* ok to cast const away here */
|
||||||
|
@ -4327,7 +4335,7 @@ static bool check_dir(const char *dirname, int add_files)
|
||||||
struct dirinfo info = dir_get_info(dir, entry);
|
struct dirinfo info = dir_get_info(dir, entry);
|
||||||
|
|
||||||
yield();
|
yield();
|
||||||
|
|
||||||
len = strlen(curpath);
|
len = strlen(curpath);
|
||||||
/* don't add an extra / for curpath == / */
|
/* don't add an extra / for curpath == / */
|
||||||
if (len <= 1) len = 0;
|
if (len <= 1) len = 0;
|
||||||
|
|
Loading…
Reference in a new issue