summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2021-08-02 22:32:15 -0400
committerWilliam Wilgus <wilgus.william@gmail.com>2021-08-02 22:32:15 -0400
commit382b52b1207fbef856cd8a881d393655f2017e1d (patch)
treefdd90707f94089fb29c065bd60f4fbfae8c39856
parent1fc4a17e1c3d774c843bdfc4f4638df2a666870e (diff)
downloadrockbox-382b52b1207fbef856cd8a881d393655f2017e1d.tar.gz
rockbox-382b52b1207fbef856cd8a881d393655f2017e1d.zip
filetypes.c filesize() guard against negative error values
buffer size is copied to an unsigned int for core_alloc Change-Id: I7b9ccab79554e55b22d39501ccb779036913258a
-rw-r--r--apps/filetypes.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/apps/filetypes.c b/apps/filetypes.c
index 7f7c198cb5..b6a557a6d2 100644
--- a/apps/filetypes.c
+++ b/apps/filetypes.c
@@ -185,7 +185,8 @@ static int filetype_count = 0;
185static unsigned char highest_attr = 0; 185static unsigned char highest_attr = 0;
186static int viewer_count = 0; 186static int viewer_count = 0;
187 187
188static int strdup_handle, strdup_bufsize, strdup_cur_idx; 188static int strdup_handle, strdup_cur_idx;
189static size_t strdup_bufsize;
189static int move_callback(int handle, void* current, void* new) 190static int move_callback(int handle, void* current, void* new)
190{ 191{
191 /*could compare to strdup_handle, but ops is only used once */ 192 /*could compare to strdup_handle, but ops is only used once */
@@ -353,13 +354,20 @@ void filetype_init(void)
353 if (fd < 0) 354 if (fd < 0)
354 return; 355 return;
355 356
356 strdup_bufsize = filesize(fd); 357 off_t filesz = filesize(fd);
357 strdup_handle = core_alloc_ex("filetypes", strdup_bufsize, &ops); 358
358 if (strdup_handle <= 0) 359 if (filesz > 0)
360 {
361 strdup_bufsize = (size_t)filesz;
362 strdup_handle = core_alloc_ex("filetypes", strdup_bufsize, &ops);
363 }
364
365 if (filesz <= 0 || strdup_handle <= 0)
359 { 366 {
360 close(fd); 367 close(fd);
361 return; 368 return;
362 } 369 }
370
363 read_builtin_types(); 371 read_builtin_types();
364 read_config(fd); 372 read_config(fd);
365 close(fd); 373 close(fd);