Commit dfa2924
committed
fix: close two file-system race windows flagged by CodeQL
Both are js/file-system-race (TOCTOU) findings:
- server/src/translation.ts ensureTraConfig: replace the existsSync-then-write
check with an atomic exclusive create (writeFileSync flag "wx"), treating
EEXIST as the intended no-op. This makes the "never clobbers an existing
project config" guarantee actually atomic instead of racy.
- binary/src/cli.ts loadJsonToBinary: open the JSON file once and fstat + read
through the same descriptor, so the size check and the read operate on one
inode. A statSync->readFileSync pair on the path could otherwise be swapped
between check and read to bypass the snapshot-input size cap.
Behavior is unchanged on the normal paths (same error messages and exit codes);
binary CLI, binary unit, and server translation suites pass.1 parent 7b2bf1c commit dfa2924
2 files changed
Lines changed: 21 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
201 | | - | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
202 | 205 | | |
203 | | - | |
| 206 | + | |
204 | 207 | | |
205 | 208 | | |
206 | 209 | | |
207 | 210 | | |
208 | 211 | | |
209 | 212 | | |
210 | 213 | | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | 214 | | |
218 | 215 | | |
219 | 216 | | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
226 | 222 | | |
227 | 223 | | |
228 | | - | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
229 | 227 | | |
230 | 228 | | |
231 | 229 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
465 | 465 | | |
466 | 466 | | |
467 | 467 | | |
468 | | - | |
469 | 468 | | |
470 | | - | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
471 | 475 | | |
472 | 476 | | |
| 477 | + | |
| 478 | + | |
473 | 479 | | |
474 | 480 | | |
475 | 481 | | |
| |||
0 commit comments