Commit d44ae5e
committed
input: fix OOM NULL-deref bugs across input_driver overlay visibility and wayland registry handlers
Five unchecked alloc + immediate-deref bugs across the shared
input dispatch core and the wayland registry/data-offer
handlers.
=== input/input_driver.c: overlay_visibility calloc ===
input_overlay_set_visibility lazily allocates the visibility
array on first call:
if (!input_st->overlay_visibility)
{
unsigned i;
input_st->overlay_visibility = (enum overlay_visibility *)calloc(
MAX_VISIBILITY, sizeof(enum overlay_visibility));
for (i = 0; i < MAX_VISIBILITY; i++)
input_st->overlay_visibility[i] = OVERLAY_VISIBILITY_DEFAULT;
}
input_st->overlay_visibility[overlay_idx] = vis;
The calloc was unchecked. Both the init loop and the final
indexed write dereference input_st->overlay_visibility - OOM
was a crash on first visibility change after the overlay was
reloaded.
Fix: NULL-check and early-return. On failure overlays stay
at their compile-time default visibility, which is strictly
better than crashing. The next call re-enters this branch
and retries the allocation (input_st->overlay_visibility is
still NULL), so transient OOM is self-healing.
=== input/common/wayland_common.c: three unchecked callocs ===
wl_current_outputs_add: surface_output_t calloc
unchecked before os->output and wl_list_insert(&os->link) that
NULL-deref. Fixed with early return false - the caller
(registry handler) treats false as 'output not tracked', which
is strictly better than crashing and is self-healing on the
next wl_registry.global re-emission.
wl_registry listener wl_output branch:
display_output_t + output_info_t callocs both unchecked before
od->output = oi / oi->global_id = id / wl_output_add_listener
NULL-derefs. Fixed with joint NULL-check, free whichever
succeeded (free(NULL) is a no-op), skip adding this output to
wl->all_outputs.
wl_data_device_handle_data_offer: data_offer_ctx
calloc unchecked before offer_data->offer and wl_data_offer_
set_user_data/add_listener NULL-deref. Fixed with early
return - consequence is a lost drag-and-drop operation on
that specific offer.
=== input/common/wayland_common_webos.c: two unchecked callocs ===
wl_registry handler for webos wl_output: twin of
the wayland_common.c fix - display_output_t + output_info_t
callocs both unchecked, with the same od->output / oi->global_id
deref pattern. Same fix.
wl_registry handler for webos wl_seat:
seat_info_t calloc unchecked before si->seat / global_id / wl
writes NULL-deref. Fixed with early return - the compositor
re-emits wl_registry.global if a retry is needed.
=== Swept-clean in the same pass ===
Verified NULL-checked in the same files:
- input_driver.c other 5 sites: input_keyboard_line_append
realloc (tmp-pattern, guarded), input_remote_new calloc,
osk realloc (tmp-pattern, guarded), overlay images malloc
(has defensive num_images=0 on failure to make the
subsequent for-loop safely iterate zero times), overlay
ol calloc (prior audit commit).
- wayland_common.c wl_read_pipe realloc (tmp-pattern,
guarded, with invariant-preserving rewind on failure from
prior commit).
- wayland_common_webos.c: g_register_ctx malloc, *wwl calloc,
g_screensaver_ctx malloc, client_name malloc - all guarded.
- input/drivers_joypad/winraw_joypad.c: 4 sites guarded.
Reachability: all five fixes are reachable on OOM. The
overlay_visibility one is the most user-facing - any
visibility change hits it. The wayland ones fire on
display/seat/drag-drop events which are compositor-driven
and arbitrarily frequent.
Scope: local to each callsite; no cross-TU changes. All
existing state-mutation invariants preserved (on failure
we skip the mutation entirely rather than half-apply it).
Thread-safety: all sites run on their respective main
dispatch threads (input main thread, wayland event loop
thread). No new concurrency introduced.
Reachability timing: the overlay_visibility bug is reachable
on the very first user-invoked overlay visibility change
under OOM and survives as a latent crash for the lifetime
of the process (the allocation is lazy, retried on each
entry until it succeeds). The wayland bugs are reachable
on any wl_registry.global or wl_data_device.data_offer event
the compositor emits - which for data_offer is every
drag-and-drop enter, and for wl_output/wl_seat is every
display-plug / input-device hotplug event.1 parent 9e840aa commit d44ae5e
3 files changed
Lines changed: 71 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
597 | 597 | | |
598 | 598 | | |
599 | 599 | | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
600 | 608 | | |
601 | 609 | | |
602 | 610 | | |
| |||
751 | 759 | | |
752 | 760 | | |
753 | 761 | | |
754 | | - | |
755 | | - | |
756 | | - | |
757 | | - | |
758 | | - | |
759 | | - | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
760 | 782 | | |
761 | 783 | | |
762 | 784 | | |
| |||
960 | 982 | | |
961 | 983 | | |
962 | 984 | | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
963 | 994 | | |
964 | 995 | | |
965 | 996 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
239 | 251 | | |
240 | 252 | | |
241 | 253 | | |
242 | 254 | | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
243 | 262 | | |
244 | 263 | | |
245 | 264 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6147 | 6147 | | |
6148 | 6148 | | |
6149 | 6149 | | |
| 6150 | + | |
| 6151 | + | |
| 6152 | + | |
| 6153 | + | |
| 6154 | + | |
| 6155 | + | |
| 6156 | + | |
| 6157 | + | |
6150 | 6158 | | |
6151 | 6159 | | |
6152 | 6160 | | |
| |||
0 commit comments