Skip to content

chroot: remove unwrap calls #7890

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions src/uu/chroot/src/chroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,9 @@ fn enter_chroot(root: &Path, skip_chdir: bool) -> UResult<()> {
let err = unsafe {
chroot(
CString::new(root.as_os_str().as_bytes().to_vec())
.unwrap()
.map_err(|e| {
ChrootError::CannotEnter("Unable to enter root directory".to_string(), e.into())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think the "unable to enter..." string should be passed

#[error("cannot chroot to {dir}: {err}", dir = .0.quote(), err = .1)]

the first arg is the path (so, root here)

})?
.as_bytes_with_nul()
.as_ptr()
.cast::<libc::c_char>(),
Expand All @@ -448,7 +450,7 @@ fn enter_chroot(root: &Path, skip_chdir: bool) -> UResult<()> {

if err == 0 {
if !skip_chdir {
std::env::set_current_dir("/").unwrap();
std::env::set_current_dir("/")?;
}
Ok(())
} else {
Expand Down
Loading