mktemp: Don't panic when getrandom failed (#11154)

This commit is contained in:
oech3
2026-03-05 07:51:39 +09:00
committed by GitHub
parent 43555b0257
commit d906b7d85a
+8 -1
View File
@@ -24,6 +24,8 @@ use std::fs;
use std::os::unix::prelude::PermissionsExt;
use rand::Rng;
use rand::SeedableRng;
use rand::rngs::SmallRng;
use tempfile::Builder;
use thiserror::Error;
@@ -510,7 +512,12 @@ fn dry_exec(tmpdir: &Path, prefix: &str, rand: usize, suffix: &str) -> PathBuf {
// Randomize.
let bytes = &mut buf[prefix.len()..prefix.len() + rand];
rand::rng().fill(bytes);
SmallRng::try_from_os_rng()
.unwrap_or_else(|_| {
//rand::rng panics if getrandom failed
SmallRng::seed_from_u64(bytes.as_ptr() as usize as u64)
})
.fill(bytes);
for byte in bytes {
*byte = match *byte % 62 {
v @ 0..=9 => v + b'0',