Commit 02be9dd
fix(runtime): fetch string_from_header must reject handle-band ids (doctor/mcp SIGSEGV) (#5560)
The doctor / mcp-list startup segfault (EXC_BAD_ACCESS at the fetch-handle
address, e.g. 0x40005/0x40006) root-causes to perry_stdlib::fetch::
string_from_header dereferencing a native registry id as a *StringHeader.
lldb on a debug bundle (doctor):
frame #0 perry_stdlib::fetch::string_from_header ldr w9,[x1,#0x4] x1=0x40002
frame #1 js_fetch_with_options
frame #2 global_this_fetch_thunk
fetch() was called with a non-string first argument — a Request/Headers object
(a Web Fetch handle, registry id in [0x40000, 0xE0000)). The codegen passes the
bare handle id into the url_ptr *StringHeader slot of
js_fetch_with_options(url_ptr, method_ptr, body_ptr, headers_json_ptr), and
string_from_header reads (*ptr).byte_len at id+4 -> deref of unmapped low
address -> SIGSEGV. Its only guard was `ptr < 0x1000` (the TAG_UNDEFINED 0x1
remnant); a 0x40002 handle clears that floor.
Non-deterministic for mcp list because whether the id+4 page is mapped at the
call depends on heap/page layout: when mapped, byte_len reads garbage and fetch
proceeds to the intended error (clean rc=1); when unmapped, SIGSEGV.
Fix: reject the whole handle band (is_handle_band, < 0x100000) in
string_from_header so a native handle is treated as 'not a string' (None)
instead of dereferenced — same robustness pattern as the inline .length /
IC-miss / class-field-guard band gates. Adds a regression test.
This is the doctor/mcp wall and is INDEPENDENT of the alias-new fix
(a9e41e163) and of the inline-.length handle-band fix (175fda498) — both touch
different code paths; a9e41e163 merely advanced doctor far enough to reach this
fetch() call.
Co-authored-by: Ralph Küpper <ralph2@skelpo.com>1 parent e24949f commit 02be9dd
1 file changed
Lines changed: 40 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
123 | 149 | | |
124 | 150 | | |
125 | 151 | | |
| |||
198 | 224 | | |
199 | 225 | | |
200 | 226 | | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
201 | 241 | | |
202 | 242 | | |
203 | 243 | | |
| |||
0 commit comments