Commit 5b73ff7
committed
tasks: fix OOM bugs across save/load/patch/database/audio/decompress/http/wifi/steam/blissbox completion paths
Swept through tasks/ looking for unchecked malloc/calloc/realloc
returns followed by dereferences that would NULL-segv on OOM.
Fixes span 12 files and 22 individual sites; split by file:
* task_save.c (5 fixes):
- task_save_handler_finished: task_data calloc was
unchecked before a memcpy(task_data, state, ...) that
NULL-derefs on OOM. Now NULL-checked; on failure the
task_set_data attachment is skipped and save_state_cb /
undo_save_state_cb consume NULL via their own NULL checks
(added below).
- save_state_cb (consumer for task_save_handler_finished):
previously assumed task_data non-NULL and called
strdup(state->path) unconditionally. Now early-returns on
NULL task_data.
- content_load_state_cb (consumer for task_load_handler_
finished): previously dereferenced load_data->size / ->data
at variable initialisation time. Now NULL-checks first,
hoisting the field reads past the guard.
- content_load_and_save_state_cb: previously dereferenced
load_data->path / ->undo_data / ->undo_size / ->flags.
Now delegates to content_load_state_cb on NULL (which
handles NULL safely) and skips the save push.
- task_load_handler_finished: on calloc failure the
old code early-returned without freeing the on-thread
'state' struct or setting a task error - a pre-existing
leak plus silent failure. Now frees state->data + state
and sets a task error so the user sees the failure.
* task_translation.c (1 fix):
- PNG decode path: raw_image_data malloc unchecked;
the indexed write in the conversion loop NULL-derefs.
NULL-check + 'goto finish' (which NULL-safely frees
raw_image_data_alpha and rpng).
* task_patch.c (2 fixes):
- apply_patch_xdelta: *targetdata malloc unchecked;
xd3_decode_memory writes into it. NULL-check + set
PATCH_TARGET_ALLOC_FAILED + goto cleanup_stream (matching
the explicit ENOSPC handling below).
- indexed patch scan: four mallocs for
name_ips_indexed / name_bps_indexed / name_ups_indexed /
name_xdelta_indexed were unchecked before four strlcpy
calls that NULL-deref. Joint NULL-check returns true
early (same observable result as no extra patches found).
* task_database.c (1 fix):
- database_info_list_iterate_found_match: db_crc +
entry_path_str mallocs unchecked before the '[0] = \\0;'
stores that NULL-deref. Joint NULL-check frees whichever
succeeded and returns SCAN_VERDICT_ERROR so the scanner
moves on to the next content entry cleanly.
* task_audio_mixer.c (2 fixes):
- task_push_audio_mixer_load: nbio->path strdup was
unchecked; downstream strdup(nbio->path) in the ogg
upload handler is UB on NULL (POSIX). NULL-check +
goto error.
- task_push_audio_mixer_load_and_play: identical twin
pattern, identical fix.
(Note: these are NOT the audio_mixer UAF that was separately
reverted upstream as 4be8b20. Those were in
audio/audio_driver.c; these are in the task enqueue path.)
* task_decompress.c (3 fixes):
- file_archived: callback_error malloc unchecked
before strlcpy. NULL-gate the error-string population
(skipping leaves task->error NULL, which task_set_error
and downstream consumers handle).
- file_decompressed: same twin pattern, same fix.
- task_decompress_handler_finished: data calloc
unchecked before data->source_file = ... write. On OOM
free source_file (which would otherwise leak via the
skipped task_set_data) and set a task error.
* task_database_cue.c (3 fixes):
- PS2 detect_ps2_game: disc_data malloc unchecked
before intfstream_read, which writes via fread (no NULL
guard on destination). NULL-check + return 0, matching
the PS1/PSP twin patterns above/below which already had
this check.
- track_extract first variant: data malloc unchecked before
intfstream_read. NULL-check + goto error.
- track_extract second variant: twin pattern, twin fix.
* task_http.c (1 fix):
- task_http_transfer_handler: http_transfer_data_t malloc
unchecked before data->data / ->len / ->headers /
->status writes. On OOM free the already-fetched 'tmp'
buffer (data was about to take ownership) and set a task
error. Moved 'bool mute;' declaration into the success
branch to avoid an unused-variable warning on the failure
branch.
* task_wifi.c (1 fix):
- task_push_wifi_connect: task->user_data malloc
unchecked before memcpy. On OOM free task->title and the
task itself, return false so the caller sees a clean
failure.
* task_content_disc.c (1 fix):
- dump-cue DUMP_STATE_WRITE_CUE: cue_data calloc
unchecked before filestream_read. NULL-gate the read;
cue_data is actually unused after the read (only passed
to free at the bottom of this block), so skipping the
read has no further consequence beyond the failed read
itself.
* task_autodetect_blissbox.c (2 fixes):
- lp_device_path LocalAlloc unchecked before
strlcpy NULL-derefs. NULL-check + 'continue' to advance
the inner SetupDiEnumDeviceInterfaces 'for (i = 0; ...;
i++)' loop to the next device interface.
- device_path malloc unchecked before the indexed
copy loop NULL-derefs. NULL-check + free the
LocalAlloc'd lp_device_path + continue.
Both 'continue' statements target the inner for-loop's i++
advance clause, which is the intended behaviour (skip this
interface, try the next). The outer 'while (!ret)' loop
increments 'index' at the bottom of its body, which is
unaffected by the inner continue.
* task_steam.c (1 fix):
- task_push_steam_core_dlc_install: both task_init
and steam_core_dlc_install_state_t calloc were unchecked
before the state->app_id / ->name / ->has_downloaded and
task->handler / ->state / ->title / ->progress / ->callback
writes that NULL-deref. Joint NULL-check frees whichever
succeeded and returns; caller is menu Steam-DLC action
with no task-return channel, so return-silently matches
the pre-patch failure mode (task would have crashed or
silently not installed) without the crash.
(This is separate from the two other steam/steam.c bugs
that are blocked on an external mist.h enum value.)
All fixes follow the same pattern: NULL-check immediately after
the alloc, clean up partial state on failure, and propagate the
error via either task_set_error, a bool/enum return, or the
next-task-iteration advance (continue). Free-on-NULL paths
exploit free(NULL) being a no-op to minimise conditional
branches.
Thread-safety: these are all on-thread modifications within the
task worker or task-dispatch thread context - task_queue.c
serialises completion callbacks on the main thread before the
task_data memory is read, so the NULL-toleration added in
completion callbacks is safe against the earlier-dispatched
worker writing NULL into task_data.
Scope: all fixes are local to individual task handlers/callbacks;
no API changes, no header changes, no cross-subsystem impact.
The task_queue.c callback dispatch contract is unchanged -
callbacks receive task_data which may be NULL if the handler
was unable to allocate it, and callbacks are now consistently
NULL-tolerant in the cases touched here.
Reachability: every fix is reachable under OOM. The
more likely user-facing cases are save_state_cb /
content_load_state_cb / content_load_and_save_state_cb
(triggered on every save-state / load-state action), and the
blissbox enumeration (triggered on every USB joypad hotplug if
blissbox support is built in).1 parent a04f966 commit 5b73ff7
12 files changed
Lines changed: 278 additions & 48 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
465 | 465 | | |
466 | 466 | | |
467 | 467 | | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
468 | 474 | | |
469 | 475 | | |
470 | 476 | | |
| |||
591 | 597 | | |
592 | 598 | | |
593 | 599 | | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
594 | 605 | | |
595 | 606 | | |
596 | 607 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
299 | 299 | | |
300 | 300 | | |
301 | 301 | | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
302 | 311 | | |
303 | 312 | | |
304 | 313 | | |
305 | 314 | | |
306 | 315 | | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
307 | 327 | | |
308 | 328 | | |
309 | 329 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
151 | | - | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
152 | 160 | | |
153 | 161 | | |
154 | 162 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
913 | 913 | | |
914 | 914 | | |
915 | 915 | | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
916 | 930 | | |
917 | 931 | | |
918 | 932 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
292 | 292 | | |
293 | 293 | | |
294 | 294 | | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
295 | 301 | | |
296 | 302 | | |
297 | 303 | | |
| |||
1515 | 1521 | | |
1516 | 1522 | | |
1517 | 1523 | | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
1518 | 1528 | | |
1519 | 1529 | | |
1520 | 1530 | | |
| |||
1669 | 1679 | | |
1670 | 1680 | | |
1671 | 1681 | | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
1672 | 1686 | | |
1673 | 1687 | | |
1674 | 1688 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
149 | 159 | | |
150 | 160 | | |
151 | 161 | | |
| |||
178 | 188 | | |
179 | 189 | | |
180 | 190 | | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
188 | 202 | | |
189 | 203 | | |
190 | 204 | | |
| |||
206 | 220 | | |
207 | 221 | | |
208 | 222 | | |
209 | | - | |
210 | | - | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
211 | 239 | | |
212 | 240 | | |
213 | 241 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
186 | | - | |
187 | 186 | | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
200 | 215 | | |
201 | 216 | | |
202 | 217 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
689 | 689 | | |
690 | 690 | | |
691 | 691 | | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
692 | 702 | | |
693 | 703 | | |
694 | 704 | | |
| |||
918 | 928 | | |
919 | 929 | | |
920 | 930 | | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
921 | 948 | | |
922 | 949 | | |
923 | 950 | | |
| |||
0 commit comments