mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-13 18:17:39 -04:00
filetypes.c filesize() guard against negative error values
buffer size is copied to an unsigned int for core_alloc Change-Id: I7b9ccab79554e55b22d39501ccb779036913258a
This commit is contained in:
parent
1fc4a17e1c
commit
382b52b120
1 changed files with 12 additions and 4 deletions
|
@ -185,7 +185,8 @@ static int filetype_count = 0;
|
||||||
static unsigned char highest_attr = 0;
|
static unsigned char highest_attr = 0;
|
||||||
static int viewer_count = 0;
|
static int viewer_count = 0;
|
||||||
|
|
||||||
static int strdup_handle, strdup_bufsize, strdup_cur_idx;
|
static int strdup_handle, strdup_cur_idx;
|
||||||
|
static size_t strdup_bufsize;
|
||||||
static int move_callback(int handle, void* current, void* new)
|
static int move_callback(int handle, void* current, void* new)
|
||||||
{
|
{
|
||||||
/*could compare to strdup_handle, but ops is only used once */
|
/*could compare to strdup_handle, but ops is only used once */
|
||||||
|
@ -353,13 +354,20 @@ void filetype_init(void)
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
strdup_bufsize = filesize(fd);
|
off_t filesz = filesize(fd);
|
||||||
strdup_handle = core_alloc_ex("filetypes", strdup_bufsize, &ops);
|
|
||||||
if (strdup_handle <= 0)
|
if (filesz > 0)
|
||||||
|
{
|
||||||
|
strdup_bufsize = (size_t)filesz;
|
||||||
|
strdup_handle = core_alloc_ex("filetypes", strdup_bufsize, &ops);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filesz <= 0 || strdup_handle <= 0)
|
||||||
{
|
{
|
||||||
close(fd);
|
close(fd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
read_builtin_types();
|
read_builtin_types();
|
||||||
read_config(fd);
|
read_config(fd);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue