You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(interpreter): Box::pin expand_word to prevent stack overflow in nested $() (#1109)
## Summary
- Box::pin `expand_word` and extract `execute_cmd_subst` helper to
prevent stack overflow from nested command substitutions
- Each `$(...)` level previously inlined the large `expand_word` async
state machine into the caller's stack frame, causing SIGABRT at ~20-30
levels
- With both futures boxed, each level uses constant stack space — depth
32 (default `max_subst_depth`) now completes safely
## Changes
- `interpreter/mod.rs`: convert `expand_word` from `async fn` to `fn ->
Pin<Box<Future>>` wrapper over `expand_word_inner`; add
`execute_cmd_subst` Box::pin-ed helper for the command substitution body
- New `stack_overflow_regression_tests.rs`: 2 tests exercising depth 32
and nested arithmetic substitution
- `specs/006-threat-model.md`: add TM-DOS-089
## Test plan
- [x] `cargo test --test stack_overflow_regression_tests` — 2 new tests
pass (previously SIGABRT)
- [x] `cargo test --all-features -- --skip ssh_supabase` — all pass
- [x] `cargo clippy --all-targets --all-features -- -D warnings` — clean
Closes#1089
Copy file name to clipboardExpand all lines: specs/006-threat-model.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1229,6 +1229,7 @@ This section maps former vulnerability IDs to the new threat ID scheme and track
1229
1229
| TM-INT-007 |`/dev/urandom` empty with `head -c`| Weak randomness — `head -c 16 /dev/urandom` returns empty string | Fix virtual device pipe handling in head builtin |
1230
1230
| TM-DOS-044 | Nested `$()` stack overflow (regression) | Process crash (SIGABRT) at depth ~50 despite #492 fix | Interpreter execution path may need separate depth tracking from lexer fix |
1231
1231
| TM-DOS-088 | Command substitution OOM via state cloning | OOM at depth N (memory ≈ N × state_size) | Dedicated `max_subst_depth` limit (default 32), separate from `max_function_depth` — **FIXED** via #1088|
1232
+
| TM-DOS-089 | Command substitution stack overflow via inlined futures | SIGABRT at ~20-30 nested $() levels | Box::pin `expand_word` and `execute_cmd_subst` to cap per-level stack — **FIXED** via #1089|
0 commit comments