Skip to content

Commit

Permalink
fix: iomanX fd bounds check clarity and signedness
Browse files Browse the repository at this point in the history
  • Loading branch information
uyjulian committed Nov 29, 2024
1 parent e3bea49 commit 94d4311
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions iop/system/iomanx/src/iomanX.c
Original file line number Diff line number Diff line change
Expand Up @@ -961,13 +961,20 @@ static iomanX_iop_file_t *new_iob(void)
{
iomanX_iop_file_t *file_table_entry;
int state;
int fd;

fd = 0;
CpuSuspendIntr(&state);
file_table_entry = file_table;
while ( (file_table_entry < &file_table[sizeof(file_table) / sizeof(file_table[0])]) && file_table_entry->device )
file_table_entry += 1;
if ( file_table_entry >= &file_table[sizeof(file_table) / sizeof(file_table[0])] )
file_table_entry = NULL;
file_table_entry = NULL;
while ( fd < (int)(sizeof(file_table) / sizeof(file_table[0])) )
{
if ( !file_table[fd].device )
{
file_table_entry = &file_table[fd];
break;
}
fd += 1;
}
// fill in "device" temporarily to mark the fd as allocated.
if ( file_table_entry )
file_table_entry->device = (iomanX_iop_device_t *)(uiptr)0xFFFFFFEC;
Expand All @@ -979,7 +986,7 @@ static iomanX_iop_file_t *new_iob(void)

static iomanX_iop_file_t *get_iob(int fd)
{
if ( (fd < 0) || ((unsigned int)fd >= (sizeof(file_table) / sizeof(file_table[0]))) || (!file_table[fd].device) )
if ( (fd < 0) || (fd >= (int)(sizeof(file_table) / sizeof(file_table[0]))) || (!file_table[fd].device) )
return NULL;
return &file_table[fd];
}
Expand Down

0 comments on commit 94d4311

Please sign in to comment.