forked from len0rd/rockbox
Fix stack overflow issues in properties plugin
Patch by Igor Poretsky Updated by Solomon Peachy Change-Id: I6b90845712ff92ce7b08b41e5ec92eb33faeff50
This commit is contained in:
parent
40da2f7ba7
commit
2a737d3e6f
1 changed files with 31 additions and 31 deletions
|
|
@ -72,30 +72,22 @@ static unsigned human_size_log(unsigned long long size)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool file_properties(char* selected_file)
|
static bool file_properties(const char* selected_file)
|
||||||
{
|
{
|
||||||
bool found = false;
|
bool found = false;
|
||||||
char tstr[MAX_PATH];
|
|
||||||
DIR* dir;
|
DIR* dir;
|
||||||
struct dirent* entry;
|
struct dirent* entry;
|
||||||
struct mp3entry id3;
|
static struct mp3entry id3;
|
||||||
|
|
||||||
char* ptr = rb->strrchr(selected_file, '/') + 1;
|
dir = rb->opendir(str_dirname);
|
||||||
int dirlen = (ptr - selected_file);
|
|
||||||
rb->strlcpy(tstr, selected_file, dirlen + 1);
|
|
||||||
|
|
||||||
dir = rb->opendir(tstr);
|
|
||||||
if (dir)
|
if (dir)
|
||||||
{
|
{
|
||||||
while(0 != (entry = rb->readdir(dir)))
|
while(0 != (entry = rb->readdir(dir)))
|
||||||
{
|
{
|
||||||
struct dirinfo info = rb->dir_get_info(dir, entry);
|
struct dirinfo info = rb->dir_get_info(dir, entry);
|
||||||
if(!rb->strcmp(entry->d_name, selected_file+dirlen))
|
if(!rb->strcmp(entry->d_name, str_filename))
|
||||||
{
|
{
|
||||||
unsigned log;
|
unsigned log;
|
||||||
rb->snprintf(str_dirname, sizeof str_dirname, "%s", tstr);
|
|
||||||
rb->snprintf(str_filename, sizeof str_filename, "%s",
|
|
||||||
selected_file+dirlen);
|
|
||||||
log = human_size_log((unsigned long)info.size);
|
log = human_size_log((unsigned long)info.size);
|
||||||
rb->snprintf(str_size, sizeof str_size, "%lu %cB",
|
rb->snprintf(str_size, sizeof str_size, "%lu %cB",
|
||||||
((unsigned long)info.size) >> (log*10), human_size_prefix[log]);
|
((unsigned long)info.size) >> (log*10), human_size_prefix[log]);
|
||||||
|
|
@ -227,34 +219,34 @@ static bool _dir_properties(DPS* dps)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool dir_properties(char* selected_file)
|
static bool dir_properties(const char* selected_file, DPS *dps)
|
||||||
{
|
{
|
||||||
unsigned log;
|
unsigned log;
|
||||||
DPS dps = {
|
|
||||||
.len = MAX_PATH,
|
rb->strlcpy(dps->dirname, selected_file, MAX_PATH);
|
||||||
.dc = 0,
|
|
||||||
.fc = 0,
|
|
||||||
.bc = 0,
|
|
||||||
};
|
|
||||||
rb->strlcpy(dps.dirname, selected_file, MAX_PATH);
|
|
||||||
|
|
||||||
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
||||||
rb->cpu_boost(true);
|
rb->cpu_boost(true);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(false == _dir_properties(&dps))
|
if (!_dir_properties(dps))
|
||||||
|
{
|
||||||
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
||||||
|
rb->cpu_boost(false);
|
||||||
|
#endif
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
||||||
rb->cpu_boost(false);
|
rb->cpu_boost(false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rb->strlcpy(str_dirname, selected_file, MAX_PATH);
|
rb->strlcpy(str_dirname, selected_file, MAX_PATH);
|
||||||
rb->snprintf(str_dircount, sizeof str_dircount, "%d", dps.dc);
|
rb->snprintf(str_dircount, sizeof str_dircount, "%d", dps->dc);
|
||||||
rb->snprintf(str_filecount, sizeof str_filecount, "%d", dps.fc);
|
rb->snprintf(str_filecount, sizeof str_filecount, "%d", dps->fc);
|
||||||
log = human_size_log(dps.bc);
|
log = human_size_log(dps->bc);
|
||||||
rb->snprintf(str_size, sizeof str_size, "%ld %cB",
|
rb->snprintf(str_size, sizeof str_size, "%ld %cB",
|
||||||
(long) (dps.bc >> (log*10)), human_size_prefix[log]);
|
(long) (dps->bc >> (log*10)), human_size_prefix[log]);
|
||||||
num_properties = 4;
|
num_properties = 4;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -293,27 +285,35 @@ enum plugin_status plugin_start(const void* parameter)
|
||||||
struct gui_synclist properties_lists;
|
struct gui_synclist properties_lists;
|
||||||
int button;
|
int button;
|
||||||
bool quit = false, usb = false;
|
bool quit = false, usb = false;
|
||||||
char file[MAX_PATH];
|
const char *file = parameter;
|
||||||
if(!parameter) return PLUGIN_ERROR;
|
if(!parameter) return PLUGIN_ERROR;
|
||||||
rb->strcpy(file, (const char *) parameter);
|
|
||||||
#ifdef HAVE_TOUCHSCREEN
|
#ifdef HAVE_TOUCHSCREEN
|
||||||
rb->touchscreen_set_mode(rb->global_settings->touch_mode);
|
rb->touchscreen_set_mode(rb->global_settings->touch_mode);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static DPS dps = {
|
||||||
|
.len = MAX_PATH,
|
||||||
|
.dc = 0,
|
||||||
|
.fc = 0,
|
||||||
|
.bc = 0,
|
||||||
|
};
|
||||||
|
|
||||||
/* determine if it's a file or a directory */
|
/* determine if it's a file or a directory */
|
||||||
bool found = false;
|
bool found = false;
|
||||||
DIR* dir;
|
DIR* dir;
|
||||||
struct dirent* entry;
|
struct dirent* entry;
|
||||||
char* ptr = rb->strrchr(file, '/') + 1;
|
char* ptr = rb->strrchr(file, '/') + 1;
|
||||||
int dirlen = (ptr - file);
|
int dirlen = (ptr - file);
|
||||||
|
|
||||||
rb->strlcpy(str_dirname, file, dirlen + 1);
|
rb->strlcpy(str_dirname, file, dirlen + 1);
|
||||||
|
rb->snprintf(str_filename, sizeof str_filename, "%s", file+dirlen);
|
||||||
|
|
||||||
dir = rb->opendir(str_dirname);
|
dir = rb->opendir(str_dirname);
|
||||||
if (dir)
|
if (dir)
|
||||||
{
|
{
|
||||||
while(0 != (entry = rb->readdir(dir)))
|
while(0 != (entry = rb->readdir(dir)))
|
||||||
{
|
{
|
||||||
if(!rb->strcmp(entry->d_name, file+dirlen))
|
if(!rb->strcmp(entry->d_name, str_filename))
|
||||||
{
|
{
|
||||||
struct dirinfo info = rb->dir_get_info(dir, entry);
|
struct dirinfo info = rb->dir_get_info(dir, entry);
|
||||||
its_a_dir = info.attribute & ATTR_DIRECTORY ? true : false;
|
its_a_dir = info.attribute & ATTR_DIRECTORY ? true : false;
|
||||||
|
|
@ -334,7 +334,7 @@ enum plugin_status plugin_start(const void* parameter)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get the info depending on its_a_dir */
|
/* get the info depending on its_a_dir */
|
||||||
if(!(its_a_dir ? dir_properties(file) : file_properties(file)))
|
if(!(its_a_dir ? dir_properties(file, &dps) : file_properties(file)))
|
||||||
{
|
{
|
||||||
/* something went wrong (to do: tell user what it was (nesting,...) */
|
/* something went wrong (to do: tell user what it was (nesting,...) */
|
||||||
rb->splash(0, "Failed to gather information");
|
rb->splash(0, "Failed to gather information");
|
||||||
|
|
@ -347,7 +347,7 @@ enum plugin_status plugin_start(const void* parameter)
|
||||||
rb->viewportmanager_theme_enable(i, true, NULL);
|
rb->viewportmanager_theme_enable(i, true, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rb->gui_synclist_init(&properties_lists, &get_props, file, false, 2, NULL);
|
rb->gui_synclist_init(&properties_lists, &get_props, &dps, false, 2, NULL);
|
||||||
rb->gui_synclist_set_title(&properties_lists, its_a_dir ?
|
rb->gui_synclist_set_title(&properties_lists, its_a_dir ?
|
||||||
"Directory properties" :
|
"Directory properties" :
|
||||||
"File properties", NOICON);
|
"File properties", NOICON);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue