Commit 1f8f298
fix(fspy): keep execveat's resolved path alive across the exec, in the per-call arena
The arena's first user moves from the fd-relative path join to execveat,
for two reasons.
The join was the wrong showcase: the benchmark suite added for it showed
the arena costing ~3% on that lane, because the code it replaced is
nearly free — getcwd() already returns a buffer with room to append, so
PathBuf::push rarely allocates at all. That code comes back unchanged.
execveat is the right one. Its resolved absolute path must be copied
into fresh NUL-terminated storage, exec runs in the child of fork() in
multithreaded programs (posix_spawn does exactly that) where malloc can
deadlock on a lock held by a vanished thread — and the previous code had
a use-after-free: it built a CString, moved it into a match arm that
extracted the raw pointer, dropped it at the arm's end, and passed the
dangling pointer to the real exec. The arena copy is borrowed from a
binding that provably outlives the exec call, and dropping CString::new
also drops its interior-NUL panic path from an interception.
execveat currently has no test coverage — which is how the dangling
pointer survived. That gap is left for a follow-up.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent 7f63a93 commit 1f8f298
2 files changed
Lines changed: 25 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | 77 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
| 78 | + | |
93 | 79 | | |
94 | | - | |
| 80 | + | |
95 | 81 | | |
96 | 82 | | |
97 | 83 | | |
| |||
Lines changed: 21 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | 3 | | |
7 | 4 | | |
8 | 5 | | |
| |||
195 | 192 | | |
196 | 193 | | |
197 | 194 | | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
198 | 201 | | |
199 | 202 | | |
200 | 203 | | |
201 | 204 | | |
202 | 205 | | |
203 | 206 | | |
204 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
205 | 216 | | |
206 | 217 | | |
207 | 218 | | |
208 | 219 | | |
209 | 220 | | |
210 | 221 | | |
211 | 222 | | |
212 | | - | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
213 | 229 | | |
214 | 230 | | |
215 | 231 | | |
| |||
0 commit comments