Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, creating a temporary file from a TLS destructor could panic in fastrand (because the thread-local RNG may have been deallocated).
Now, we fork the RNG before we create each file, falling back on an RNG with a static seed if the thread-local RNG has been deallocated.
Two downsides to this patch:
getrandom
re-seed kicks in (assuming that feature is enabled). IMO, that's fine; this would panic previously.getrandom
re-seeding used to re-randomize to the entire per-thread RNG, now it only applies to the per-filename RNG. However, the will still serve its purpose as a mitigation against potential DoS attacks.I also considered managing the thread-local RNG myself instead of relying on fastrand, but that just isn't worth the added code, IMO.
Thanks to @stoeckmann for reporting this and explaining the issue to me. I went with this version instead of their version because I needed to keep
tmpname
as a separate function for some tempfile v4 changes.fixes #281
NOTE: there are no tests because I can't actually trigger a crash no matter how I write the test. My test TLS slot is always deallocated first.