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

Don't error out on truncated values #52

Merged
merged 1 commit into from
Apr 14, 2022
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/unix/funcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,11 @@ pub fn value_oid(oid: &mut Vec<i32>) -> Result<CtlValue, SysctlError> {

// Confirm that we did not read out of bounds
assert!(new_val_len <= val_len);
// Confirm that we got the bytes we requested
// The call can sometimes return bytes that are smaller than initially indicated, so it should
// be safe to truncate it. See a similar approach in golang module:
// https://github.com/golang/sys/blob/43e60d72a8e2bd92ee98319ba9a384a0e9837c08/unix/syscall_bsd.go#L545-L548
if new_val_len < val_len {
return Err(SysctlError::ShortRead {
read: new_val_len,
reported: val_len,
});
val.truncate(new_val_len);
}

// Wrap in Enum and return
Expand Down