Commit b21a6b9
committed
json: bounds-check \uXXXX escape before MustMove
Reaching `case 'u'` in the JSON string-escape switch only proved the
cursor sits on the `u` byte. `StrIterMustMove(&si, 5)` then consumed
the `u` plus four hex digits without ever checking that the four
digits exist -- crafted input like `"\u"` / `"\u1"` / `"\u12"` /
`"\u123"` tripped LOG_FATAL inside the parser, aborting any caller
that ingests untrusted JSON. Guard with RemainingLength >= 5 and
bail to saved_si on truncation, matching the bool/null arms.
Codify the rule: *Must* APIs are only safe when the callsite has
statically proven the precondition (peek-then-Must, bounds-then-Must,
or a caller-stage validated window). Auditing every Must site in the
codebase against this rule turned up no other unsafe call -- all
parser Must sites are dominated by elf_range_ok / cmdsize windows,
RemainingLength checks, or peek-guarded while bodies.1 parent 6b8114e commit b21a6b9
2 files changed
Lines changed: 45 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
402 | 402 | | |
403 | 403 | | |
404 | 404 | | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
405 | 440 | | |
406 | 441 | | |
407 | 442 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
255 | 255 | | |
256 | 256 | | |
257 | 257 | | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
258 | 268 | | |
259 | 269 | | |
260 | 270 | | |
| |||
0 commit comments