Commit 940b809
fix(cli): fix secure_getenv() bypass of one-shot token protection (#1244)
* fix(cli): fix secure_getenv() bypass of one-shot token protection
secure_getenv() was calling get_token_index() before init_token_list()
and without the mutex, causing all token protection to be bypassed when
secure_getenv() was the first call into the library (empty token list
returns -1 for all lookups). Added initialization, mutex acquisition,
and recursion guard matching the getenv() implementation.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: move token init to constructor to prevent contention
Multi-threaded programs like rustc call getenv() from many threads during
startup. The previous fix held the mutex for every getenv() call to protect
lazy initialization, which serialized all threads and caused rustc to
timeout (60s) in CI.
Move init_token_list() into the library constructor which runs before any
threads are created. This eliminates the data race without needing the
mutex for non-sensitive variable lookups.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 9b55519 commit 940b809
1 file changed
+22
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
295 | 295 | | |
296 | 296 | | |
297 | 297 | | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
298 | 304 | | |
299 | 305 | | |
300 | 306 | | |
| |||
331 | 337 | | |
332 | 338 | | |
333 | 339 | | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
| 340 | + | |
| 341 | + | |
341 | 342 | | |
342 | 343 | | |
343 | | - | |
| 344 | + | |
344 | 345 | | |
345 | | - | |
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
349 | 349 | | |
350 | | - | |
| 350 | + | |
| 351 | + | |
351 | 352 | | |
352 | 353 | | |
353 | 354 | | |
| |||
404 | 405 | | |
405 | 406 | | |
406 | 407 | | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
407 | 416 | | |
408 | 417 | | |
409 | 418 | | |
410 | 419 | | |
| 420 | + | |
411 | 421 | | |
412 | 422 | | |
413 | 423 | | |
414 | | - | |
| 424 | + | |
415 | 425 | | |
416 | | - | |
417 | 426 | | |
418 | 427 | | |
419 | 428 | | |
| |||
445 | 454 | | |
446 | 455 | | |
447 | 456 | | |
| 457 | + | |
448 | 458 | | |
449 | 459 | | |
450 | 460 | | |
0 commit comments