Security context

What an agent needs to avoid regressing past fixes and find the next vuln in this repo.

rust-random/rand
master @ bea8620
3
Fixes
1
CVEs
CRITICAL
Peak severity
Highlights
Memory Safety: 2 prior fixes. Scrutinize any change in this area.
src/libcore/rand.rs: most-fixed (1 issue). Treat as high-risk during review.
1 high-severity fix in this history; regressions here are high-impact.
Recurring patterns

The bug types that recur here, drawn from past fixes, not open vulnerabilities.

Memory Safety: The library historical utilized unsafe FFI boundaries that passed owned slice objects rather than explicit buffer-pointer and size-argument pairs. This created a high risk of memory unsafety and memory corruption when interacting with the underlying Rust runtime APIs (`rustrt::rand_seed` and `rustrt::rand_new_seeded2`).
Memory Safety: Using unsafe type casting (such as `cast::transmute` and `cast::transmute_copy`) on slices in performance-critical paths like `Rng.fill_bytes` historically introduced undefined behavior due to alignment issues, similar to problems tracked in CVE-2020-25576.
Race Condition: Using relaxed atomics to check the availability of OS-specific entropy sources created a race condition during initialization, which required synchronization using `std::sync::Once` to resolve safely.