Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solaris: Do not read from errno when libc did not indicate error. #448

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/solaris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
let ptr = chunk.as_mut_ptr().cast::<c_void>();
let ret = unsafe { libc::getrandom(ptr, chunk.len(), libc::GRND_RANDOM) };
// In case the man page has a typo, we also check for negative ret.
if ret <= 0 {
return Err(last_os_error());
}
// If getrandom(2) succeeds, it should have completely filled chunk.
if (ret as usize) != chunk.len() {
return Err(Error::UNEXPECTED);
match usize::try_from(ret) {
Ok(ret) if ret == chunk.len() => {} // Good. Keep going.
Ok(0) => return Err(last_os_error()), // The syscall failed.
_ => return Err(Error::UNEXPECTED),
}
}
Ok(())
Expand Down
Loading