file_list: return NULL from the at-offset accessors for an index past size

file_list_get_userdata_at_offset and file_list_get_actiondata_at_offset
checked the list pointer but not the index, so any caller with a stale
or computed index read item_file fields past the end of the allocation.
Every menu driver resolves nodes through these accessors with indices
derived from a different list than the one being indexed (selection
ordinals, entry_idx values, name-match loop cursors), and each such
site has had to carry its own bounds check; the ones that did not are
the ozone icon lookups fixed in the previous commit, one of which
crashed in the wild. An out-of-range index now resolves to NULL, the
same answer callers already take for a missing node.

The call-site guards stay: they are one compare, they document why the
index can be out of range at each site, and they keep the sites correct
against any other accessor. The header-icon comment that pointed at the
unchecked accessor is reworded to match.
This commit is contained in:
LibretroAdmin authored and libretroadmin committed 2026-08-30 16:04:14 +02:00
1 parent 308c78157c
commit e8679e552d
2 files changed
+4 -6

No files matched your search

+2 -2
View File
@@ -328,14 +328,14 @@ void file_list_sort_on_type(file_list_t *list)
void *file_list_get_userdata_at_offset(const file_list_t *list, size_t idx)
{
if (!list)
if (!list || idx >= list->size)
return NULL;
return list->list[idx].userdata;
}
void *file_list_get_actiondata_at_offset(const file_list_t *list, size_t idx)
{
if (!list)
if (!list || idx >= list->size)
return NULL;
return list->list[idx].actiondata;
}
+2 -4
View File
@@ -13115,10 +13115,8 @@ static void ozone_set_header(ozone_handle_t *ozone)
break;
}
/* A missed match must resolve to no node; the accessor
* does not bounds-check, so indexing with offset ==
* size reads one entry past the end of the list and the
* garbage is then dereferenced below. */
/* A missed match leaves offset == size and must resolve
* to no node. */
node = (offset < ozone->horizontal_list.size)
? (ozone_node_t*)file_list_get_userdata_at_offset(
&ozone->horizontal_list, offset)