summaryrefslogtreecommitdiff
path: root/apps/plugins/properties.c
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2019-07-24 14:08:56 -0400
committerSolomon Peachy <pizza@shaftnet.org>2019-08-05 03:25:17 +0200
commit2a737d3e6f028c68b9c97723f4f14025d74860af (patch)
tree43d67fcd279e456edd121d499c671c2f65340835 /apps/plugins/properties.c
parent40da2f7ba7619d4c24be36e884f799ff8714e907 (diff)
downloadrockbox-2a737d3e6f028c68b9c97723f4f14025d74860af.tar.gz
rockbox-2a737d3e6f028c68b9c97723f4f14025d74860af.zip
Fix stack overflow issues in properties plugin
Patch by Igor Poretsky Updated by Solomon Peachy Change-Id: I6b90845712ff92ce7b08b41e5ec92eb33faeff50
Diffstat (limited to 'apps/plugins/properties.c')
-rw-r--r--apps/plugins/properties.c62
1 files changed, 31 insertions, 31 deletions
diff --git a/apps/plugins/properties.c b/apps/plugins/properties.c
index 3115da94a4..3bddc24d69 100644
--- a/apps/plugins/properties.c
+++ b/apps/plugins/properties.c
@@ -72,30 +72,22 @@ static unsigned human_size_log(unsigned long long size)
72 return i; 72 return i;
73} 73}
74 74
75static bool file_properties(char* selected_file) 75static bool file_properties(const char* selected_file)
76{ 76{
77 bool found = false; 77 bool found = false;
78 char tstr[MAX_PATH];
79 DIR* dir; 78 DIR* dir;
80 struct dirent* entry; 79 struct dirent* entry;
81 struct mp3entry id3; 80 static struct mp3entry id3;
82 81
83 char* ptr = rb->strrchr(selected_file, '/') + 1; 82 dir = rb->opendir(str_dirname);
84 int dirlen = (ptr - selected_file);
85 rb->strlcpy(tstr, selected_file, dirlen + 1);
86
87 dir = rb->opendir(tstr);
88 if (dir) 83 if (dir)
89 { 84 {
90 while(0 != (entry = rb->readdir(dir))) 85 while(0 != (entry = rb->readdir(dir)))
91 { 86 {
92 struct dirinfo info = rb->dir_get_info(dir, entry); 87 struct dirinfo info = rb->dir_get_info(dir, entry);
93 if(!rb->strcmp(entry->d_name, selected_file+dirlen)) 88 if(!rb->strcmp(entry->d_name, str_filename))
94 { 89 {
95 unsigned log; 90 unsigned log;
96 rb->snprintf(str_dirname, sizeof str_dirname, "%s", tstr);
97 rb->snprintf(str_filename, sizeof str_filename, "%s",
98 selected_file+dirlen);
99 log = human_size_log((unsigned long)info.size); 91 log = human_size_log((unsigned long)info.size);
100 rb->snprintf(str_size, sizeof str_size, "%lu %cB", 92 rb->snprintf(str_size, sizeof str_size, "%lu %cB",
101 ((unsigned long)info.size) >> (log*10), human_size_prefix[log]); 93 ((unsigned long)info.size) >> (log*10), human_size_prefix[log]);
@@ -160,7 +152,7 @@ typedef struct {
160 unsigned long long bc; 152 unsigned long long bc;
161} DPS; 153} DPS;
162 154
163static bool _dir_properties(DPS* dps) 155static bool _dir_properties(DPS *dps)
164{ 156{
165 /* recursively scan directories in search of files 157 /* recursively scan directories in search of files
166 and informs the user of the progress */ 158 and informs the user of the progress */
@@ -227,34 +219,34 @@ static bool _dir_properties(DPS* dps)
227 return result; 219 return result;
228} 220}
229 221
230static bool dir_properties(char* selected_file) 222static bool dir_properties(const char* selected_file, DPS *dps)
231{ 223{
232 unsigned log; 224 unsigned log;
233 DPS dps = { 225
234 .len = MAX_PATH, 226 rb->strlcpy(dps->dirname, selected_file, MAX_PATH);
235 .dc = 0,
236 .fc = 0,
237 .bc = 0,
238 };
239 rb->strlcpy(dps.dirname, selected_file, MAX_PATH);
240 227
241#ifdef HAVE_ADJUSTABLE_CPU_FREQ 228#ifdef HAVE_ADJUSTABLE_CPU_FREQ
242 rb->cpu_boost(true); 229 rb->cpu_boost(true);
243#endif 230#endif
244 231
245 if(false == _dir_properties(&dps)) 232 if (!_dir_properties(dps))
233 {
234#ifdef HAVE_ADJUSTABLE_CPU_FREQ
235 rb->cpu_boost(false);
236#endif
246 return false; 237 return false;
238 }
247 239
248#ifdef HAVE_ADJUSTABLE_CPU_FREQ 240#ifdef HAVE_ADJUSTABLE_CPU_FREQ
249 rb->cpu_boost(false); 241 rb->cpu_boost(false);
250#endif 242#endif
251 243
252 rb->strlcpy(str_dirname, selected_file, MAX_PATH); 244 rb->strlcpy(str_dirname, selected_file, MAX_PATH);
253 rb->snprintf(str_dircount, sizeof str_dircount, "%d", dps.dc); 245 rb->snprintf(str_dircount, sizeof str_dircount, "%d", dps->dc);
254 rb->snprintf(str_filecount, sizeof str_filecount, "%d", dps.fc); 246 rb->snprintf(str_filecount, sizeof str_filecount, "%d", dps->fc);
255 log = human_size_log(dps.bc); 247 log = human_size_log(dps->bc);
256 rb->snprintf(str_size, sizeof str_size, "%ld %cB", 248 rb->snprintf(str_size, sizeof str_size, "%ld %cB",
257 (long) (dps.bc >> (log*10)), human_size_prefix[log]); 249 (long) (dps->bc >> (log*10)), human_size_prefix[log]);
258 num_properties = 4; 250 num_properties = 4;
259 return true; 251 return true;
260} 252}
@@ -293,27 +285,35 @@ enum plugin_status plugin_start(const void* parameter)
293 struct gui_synclist properties_lists; 285 struct gui_synclist properties_lists;
294 int button; 286 int button;
295 bool quit = false, usb = false; 287 bool quit = false, usb = false;
296 char file[MAX_PATH]; 288 const char *file = parameter;
297 if(!parameter) return PLUGIN_ERROR; 289 if(!parameter) return PLUGIN_ERROR;
298 rb->strcpy(file, (const char *) parameter);
299#ifdef HAVE_TOUCHSCREEN 290#ifdef HAVE_TOUCHSCREEN
300 rb->touchscreen_set_mode(rb->global_settings->touch_mode); 291 rb->touchscreen_set_mode(rb->global_settings->touch_mode);
301#endif 292#endif
302 293
294 static DPS dps = {
295 .len = MAX_PATH,
296 .dc = 0,
297 .fc = 0,
298 .bc = 0,
299 };
300
303 /* determine if it's a file or a directory */ 301 /* determine if it's a file or a directory */
304 bool found = false; 302 bool found = false;
305 DIR* dir; 303 DIR* dir;
306 struct dirent* entry; 304 struct dirent* entry;
307 char* ptr = rb->strrchr(file, '/') + 1; 305 char* ptr = rb->strrchr(file, '/') + 1;
308 int dirlen = (ptr - file); 306 int dirlen = (ptr - file);
307
309 rb->strlcpy(str_dirname, file, dirlen + 1); 308 rb->strlcpy(str_dirname, file, dirlen + 1);
309 rb->snprintf(str_filename, sizeof str_filename, "%s", file+dirlen);
310 310
311 dir = rb->opendir(str_dirname); 311 dir = rb->opendir(str_dirname);
312 if (dir) 312 if (dir)
313 { 313 {
314 while(0 != (entry = rb->readdir(dir))) 314 while(0 != (entry = rb->readdir(dir)))
315 { 315 {
316 if(!rb->strcmp(entry->d_name, file+dirlen)) 316 if(!rb->strcmp(entry->d_name, str_filename))
317 { 317 {
318 struct dirinfo info = rb->dir_get_info(dir, entry); 318 struct dirinfo info = rb->dir_get_info(dir, entry);
319 its_a_dir = info.attribute & ATTR_DIRECTORY ? true : false; 319 its_a_dir = info.attribute & ATTR_DIRECTORY ? true : false;
@@ -334,7 +334,7 @@ enum plugin_status plugin_start(const void* parameter)
334 } 334 }
335 335
336 /* get the info depending on its_a_dir */ 336 /* get the info depending on its_a_dir */
337 if(!(its_a_dir ? dir_properties(file) : file_properties(file))) 337 if(!(its_a_dir ? dir_properties(file, &dps) : file_properties(file)))
338 { 338 {
339 /* something went wrong (to do: tell user what it was (nesting,...) */ 339 /* something went wrong (to do: tell user what it was (nesting,...) */
340 rb->splash(0, "Failed to gather information"); 340 rb->splash(0, "Failed to gather information");
@@ -347,7 +347,7 @@ enum plugin_status plugin_start(const void* parameter)
347 rb->viewportmanager_theme_enable(i, true, NULL); 347 rb->viewportmanager_theme_enable(i, true, NULL);
348#endif 348#endif
349 349
350 rb->gui_synclist_init(&properties_lists, &get_props, file, false, 2, NULL); 350 rb->gui_synclist_init(&properties_lists, &get_props, &dps, false, 2, NULL);
351 rb->gui_synclist_set_title(&properties_lists, its_a_dir ? 351 rb->gui_synclist_set_title(&properties_lists, its_a_dir ?
352 "Directory properties" : 352 "Directory properties" :
353 "File properties", NOICON); 353 "File properties", NOICON);