Commit b569dd0
committed
Four independent defensive fixes, all bundled into a single combined
commit on top of master `b2d4002`. No CI workflow changes required.
```
round4_delivery/
├── round4-combined.patch single unified patch, ~566 lines
├── commit_message.msg just the commit message body
├── README.md this file
└── libretro-common-samples/
└── file/
├── config_file/config_file_test.c extended sample
└── nbio/nbio_test.c extended + cleaned-up sample
```
To apply:
```
cd RetroArch
git apply round4-combined.patch
git add -A
git commit -F round4_delivery/commit_message.msg
```
Or in one step with `git am`:
```
git am round4-combined.patch
```
Full technical detail lives in the patch's commit message; the
summary here is for quick reference.
| # | File | What |
|---|---|---|
| 11 | `file/config_file.c` | NULL dangling pointer fields in `config_file_deinitialize` |
| 12 | `file/config_file.c` | Check strdup return at three call sites |
| 13 | `file/config_file.c` | `isgraph((int)char)` UB → cast to `unsigned char` |
| 14 | `file/nbio/nbio_stdio.c` | `nbio_stdio_resize` realloc-before-commit |
All four are "latent landmine" tier — correct today only because of
indirect invariants or benign libc behaviour, not because of active
exploitable corruption. Exception: patch 11 has a reachable UAF
under a specific public-API usage pattern (demonstrated via ASan
during test development).
If triaging: 11 > 12 > 14 > 13.
| Test | Kind | What it shows |
|---|---|---|
| `test_config_file_deinitialize_clears_fields` | **True regression discriminator** | Fails on unpatched source: `[FAILED] deinit left entries as dangling 0x...`; passes on patched |
| `test_config_file_high_bit_bytes_smoke` | Smoke test | glibc doesn't fire on the pre-patch code so this passes on both sides on a typical Linux host. Value: would trip under UBSan ctype instrumentation pre-patch, and crashes on stricter libcs pre-patch. Documented in the test comment. |
| `nbio_resize_smoke_test` | Smoke test | Forcing realloc to fail from user code would need an allocator hook, which breaks the self-contained-sample convention. Exercises the resize grow path normally; ASan catches buffer/length disagreement. |
Honest note on test coverage: patch 12 (the strdup chain) has no
targeted regression test. The failure modes are all OOM-triggered,
and exercising them would require either an allocator hook or
deliberately exhausting memory — both out of scope for the
self-contained sample convention. The existing config_file_test
cases implicitly exercise the non-OOM code paths, so a refactor
that breaks the happy path would still be caught.
While I was extending `nbio_test.c` I fixed two pre-existing issues
that would have bit the CI workflow:
* Return 0 regardless of `[ERROR]` output → now returns 1 if any
`[ERROR]` was printed. This makes the test a real pass/fail
signal for CI rather than just a build smoke.
* Left `test.bin` in CWD after running → now cleans up.
Also adds cleanup of the new `resize_test.bin` used by the
resize smoke test.
For each patch:
1. **Patch first, then test.** Applied each patch to the tree,
confirmed clean compile with `-Wall -Werror`, and confirmed the
existing sample tests still pass.
2. **Test against patched source.** Ran the new tests expecting
they pass.
3. **Revert the source, keep the tests.** Ran the tests again.
For patch 11 this fired the documented `[FAILED]` message; for
13 and 14 the smoke tests passed on both sides (documented as
smoke tests, not discriminators).
The patch 11 UAF was not just hypothetical — during test
development I reproduced a concrete heap-use-after-free (ASan
trace via `config_file_add_reference` after `config_file_deinitialize`
on the same struct).
- **14 patches** merged (across rounds 1-3) + **4 patches** this round = **18 total**
- **7 regression test files** + extensions this round
- **1 CI workflow** (added round 3 work)
- Every round verified by discrimination-test methodology where
feasible; smoke-test-labelled where not1 parent b2d4002 commit b569dd0
4 files changed
Lines changed: 323 additions & 10 deletions
File tree
- libretro-common
- file
- nbio
- samples/file
- config_file
- nbio
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
249 | | - | |
| 249 | + | |
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
| |||
380 | 380 | | |
381 | 381 | | |
382 | 382 | | |
383 | | - | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
384 | 388 | | |
385 | 389 | | |
386 | 390 | | |
| |||
393 | 397 | | |
394 | 398 | | |
395 | 399 | | |
| 400 | + | |
396 | 401 | | |
397 | 402 | | |
398 | 403 | | |
| |||
569 | 574 | | |
570 | 575 | | |
571 | 576 | | |
572 | | - | |
| 577 | + | |
573 | 578 | | |
574 | 579 | | |
575 | 580 | | |
| |||
705 | 710 | | |
706 | 711 | | |
707 | 712 | | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
708 | 730 | | |
709 | 731 | | |
710 | 732 | | |
| |||
1116 | 1138 | | |
1117 | 1139 | | |
1118 | 1140 | | |
| 1141 | + | |
1119 | 1142 | | |
1120 | 1143 | | |
1121 | 1144 | | |
1122 | 1145 | | |
1123 | | - | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
1124 | 1154 | | |
1125 | 1155 | | |
1126 | 1156 | | |
| |||
1239 | 1269 | | |
1240 | 1270 | | |
1241 | 1271 | | |
| 1272 | + | |
1242 | 1273 | | |
1243 | 1274 | | |
1244 | | - | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
1245 | 1286 | | |
1246 | 1287 | | |
1247 | 1288 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
255 | 265 | | |
256 | 266 | | |
257 | 267 | | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | 268 | | |
264 | 269 | | |
265 | 270 | | |
| |||
Lines changed: 149 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
230 | 376 | | |
231 | 377 | | |
232 | 378 | | |
| |||
267 | 413 | | |
268 | 414 | | |
269 | 415 | | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
270 | 419 | | |
0 commit comments