Commit d5e598a
committed
menu/materialui: fix three heap-safety issues found during audit pass
Three independent issues found during a focused audit of menu/
drivers/materialui.c. One is a real heap overflow in the status-bar
metadata builder driven by user-controllable input strings; one is
an OOB write/read on power-user-sized playlist counts; one is a
TOCTOU OOB read in the touch-tap handler. Same audit class as the
recent xmb (9a27e66) and ozone (d56c728) commits, grouped together
because they share an audit context and none is large enough to
stand alone.
* status-bar metadata: heap overflow via _len underflow in
strlcpy chain (menu/drivers/materialui.c)
materialui_render_process_entry_playlist_desktop builds the
status-bar metadata string ("Core: <name> ⠀ <runtime> ⠀ <last
played>") through a chain of six
_len += strlcpy(buf + _len, src, sizeof(buf) - _len);
calls. This pattern is NOT self-bounding: strlcpy returns
strlen(src), not bytes-actually-written, so when any intermediate
call truncates -- because the source is longer than the remaining
buffer space -- _len overshoots sizeof(status_bar.str). The next
iteration's `sizeof(...) - _len` underflows size_t to ~SIZE_MAX,
the strlcpy treats the destination as essentially infinite, and
writes proceed past status_bar.str into adjacent struct fields
(runtime_fallback_str, last_played_fallback_str, then whatever
follows in materialui_handle_t on the heap).
Reachable via any path that produces a long source string: a
crafted playlist entry with an outsize core_name, a long runtime
log entry, or a verbose locale translation of
MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_CORE.
Convert the chain to strlcpy_append, the bound-checked replacement
added in 78c52ab and applied across the codebase in 25ade82 /
e446242. After truncation strlcpy_append clamps *pos to len-1 so
the chain short-circuits cleanly instead of propagating an
underflow.
* playlist_selection[]: OOB write/read for users with too many
playlists (menu/drivers/materialui.c)
mui->playlist_selection is sized [NAME_MAX_LENGTH], which is the
*file/dir name length cap* (128 on small builds, 256 on default)
-- the wrong constant for what's actually a per-playlist-tab
remembered-selection cache. materialui_navigation_set writes
mui->playlist_selection[mui->playlist_selection_ptr] = selection;
with no bound check on the index, where the index is the user's
row in the playlists tab (also stored unchecked one branch
above). A user with > NAME_MAX_LENGTH playlists -- not implausible
for someone with FBNeo, MAME, and every console they own --
navigating to row N and then entering any playlist will OOB-write
at offset N into adjacent struct fields and the heap beyond. The
read site in materialui_populate_entries has the matching OOB
read.
Two-part fix. Replace NAME_MAX_LENGTH with a purpose-built
MUI_PLAYLIST_SELECTION_MAX (1024 -- comfortable headroom for any
plausible setup, ~8 KB cache on mui). Bound-check both the write
and read against that constant. Selections in slots beyond
MUI_PLAYLIST_SELECTION_MAX simply aren't remembered; falling
through to the existing default-selection behaviour is
preferable to a heap corruption.
* materialui_pointer_up TAP path: OOB read on stale ptr
(menu/drivers/materialui.c)
The TAP-gesture branch does
list = MENU_LIST_GET_SELECTION(menu_list, 0);
if (!list)
break;
if (!(node = (materialui_node_t*)list->list[ptr].userdata))
break;
with no bound check on ptr against list->size. ptr was set in a
prior render frame's hit-test loop, where it was bounded by that
frame's entries_end. Between render and event delivery the list
can be repopulated -- search filter applied, navigation back/
forward, async list rebuild -- leaving ptr stale and possibly
past the new list end.
The neighbouring LONG_PRESS branch (line ~11199) and the swipe
handler at materialui_pointer_up_swipe_horz_default (line ~10874)
both already guard with `ptr < entries_end`; the TAP path missed
the same defence. Add it.1 parent 14a6f8f commit d5e598a
1 file changed
Lines changed: 64 additions & 27 deletions
File tree
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
154 | 163 | | |
155 | 164 | | |
156 | 165 | | |
| |||
677 | 686 | | |
678 | 687 | | |
679 | 688 | | |
680 | | - | |
| 689 | + | |
681 | 690 | | |
682 | 691 | | |
683 | 692 | | |
| |||
3742 | 3751 | | |
3743 | 3752 | | |
3744 | 3753 | | |
3745 | | - | |
3746 | | - | |
3747 | | - | |
3748 | | - | |
3749 | | - | |
3750 | | - | |
3751 | | - | |
3752 | | - | |
3753 | | - | |
3754 | | - | |
3755 | | - | |
3756 | | - | |
3757 | | - | |
3758 | | - | |
3759 | | - | |
3760 | | - | |
3761 | | - | |
3762 | | - | |
3763 | | - | |
3764 | | - | |
3765 | | - | |
3766 | | - | |
| 3754 | + | |
| 3755 | + | |
| 3756 | + | |
| 3757 | + | |
| 3758 | + | |
| 3759 | + | |
| 3760 | + | |
| 3761 | + | |
| 3762 | + | |
| 3763 | + | |
| 3764 | + | |
| 3765 | + | |
| 3766 | + | |
| 3767 | + | |
| 3768 | + | |
| 3769 | + | |
| 3770 | + | |
| 3771 | + | |
| 3772 | + | |
| 3773 | + | |
| 3774 | + | |
| 3775 | + | |
| 3776 | + | |
| 3777 | + | |
| 3778 | + | |
| 3779 | + | |
| 3780 | + | |
| 3781 | + | |
| 3782 | + | |
| 3783 | + | |
3767 | 3784 | | |
3768 | 3785 | | |
3769 | 3786 | | |
| |||
9414 | 9431 | | |
9415 | 9432 | | |
9416 | 9433 | | |
9417 | | - | |
| 9434 | + | |
| 9435 | + | |
| 9436 | + | |
| 9437 | + | |
| 9438 | + | |
| 9439 | + | |
| 9440 | + | |
| 9441 | + | |
9418 | 9442 | | |
9419 | 9443 | | |
9420 | 9444 | | |
| |||
9830 | 9854 | | |
9831 | 9855 | | |
9832 | 9856 | | |
9833 | | - | |
| 9857 | + | |
9834 | 9858 | | |
| 9859 | + | |
9835 | 9860 | | |
9836 | 9861 | | |
9837 | 9862 | | |
| |||
11112 | 11137 | | |
11113 | 11138 | | |
11114 | 11139 | | |
11115 | | - | |
| 11140 | + | |
| 11141 | + | |
| 11142 | + | |
| 11143 | + | |
| 11144 | + | |
| 11145 | + | |
| 11146 | + | |
| 11147 | + | |
| 11148 | + | |
| 11149 | + | |
| 11150 | + | |
| 11151 | + | |
| 11152 | + | |
11116 | 11153 | | |
11117 | | - | |
| 11154 | + | |
11118 | 11155 | | |
11119 | 11156 | | |
11120 | 11157 | | |
| |||
0 commit comments