Skip to content

Commit 989c19b

Browse files
committed
fix perm width and things
1 parent a51d7f5 commit 989c19b

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

src/shims/unix/fs.rs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,53 +1668,51 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
16681668
fn chmod(&mut self, path_op: &OpTy<'tcx>, perm_op: &OpTy<'tcx>) -> InterpResult<'tcx, Scalar> {
16691669
let this = self.eval_context_mut();
16701670

1671-
// Permissions::from_mode is Unix-specific.
1672-
this.assert_target_os_is_unix("chmod");
1671+
let pathname = this.read_path_from_c_str(this.read_pointer(path_op)?)?;
1672+
let perm = this.read_scalar(perm_op)?.to_uint(this.libc_ty_layout("mode_t").size)?;
1673+
1674+
// Reject if isolation is enabled.
1675+
if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
1676+
this.reject_in_isolation("`chmod`", reject_with)?;
1677+
return this.set_last_error_and_return_i32(LibcError("EACCES"));
1678+
}
16731679

1680+
// Permissions::from_mode is Unix-specific.
16741681
#[cfg(unix)]
16751682
{
16761683
use std::os::unix::fs::PermissionsExt;
16771684

1678-
let pathname = this.read_path_from_c_str(this.read_pointer(path_op)?)?;
1679-
let perm = this.read_scalar(perm_op)?.to_u32()?;
1680-
1681-
// Reject if isolation is enabled.
1682-
if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
1683-
this.reject_in_isolation("`chmod`", reject_with)?;
1684-
return this.set_last_error_and_return_i32(LibcError("EACCES"));
1685-
}
1686-
1687-
let result = std::fs::set_permissions(pathname, Permissions::from_mode(perm));
1685+
let result = std::fs::set_permissions(
1686+
pathname,
1687+
Permissions::from_mode(perm.try_into().unwrap()),
1688+
);
16881689
let result = this.try_unwrap_io_result(result.map(|_| 0i32))?;
16891690

16901691
interp_ok(Scalar::from_i32(result))
16911692
}
16921693
#[cfg(not(unix))]
16931694
{
1694-
unreachable!()
1695+
throw_unsup_format!("`chmod` is not supported on this platform")
16951696
}
16961697
}
16971698

16981699
fn fchmod(&mut self, fd_op: &OpTy<'tcx>, perm_op: &OpTy<'tcx>) -> InterpResult<'tcx, Scalar> {
16991700
let this = self.eval_context_mut();
17001701

1701-
// `Permissions::from_mode` is Unix-specific.
1702-
this.assert_target_os_is_unix("fchmod");
1702+
let fd = this.read_scalar(fd_op)?.to_i32()?;
1703+
let perm = this.read_scalar(perm_op)?.to_uint(this.libc_ty_layout("mode_t").size)?;
17031704

1705+
// Reject if isolation is enabled.
1706+
if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
1707+
this.reject_in_isolation("`fchmod`", reject_with)?;
1708+
// Set error code as "EBADF" (bad fd)
1709+
return this.set_last_error_and_return_i32(LibcError("EBADF"));
1710+
}
1711+
// `Permissions::from_mode` is Unix-specific.
17041712
#[cfg(unix)]
17051713
{
17061714
use std::os::unix::fs::PermissionsExt;
17071715

1708-
let fd = this.read_scalar(fd_op)?.to_i32()?;
1709-
let perm = this.read_scalar(perm_op)?.to_u32()?;
1710-
1711-
// Reject if isolation is enabled.
1712-
if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
1713-
this.reject_in_isolation("`fchmod`", reject_with)?;
1714-
// Set error code as "EBADF" (bad fd)
1715-
return this.set_last_error_and_return_i32(LibcError("EBADF"));
1716-
}
1717-
17181716
let Some(fd) = this.machine.fds.get(fd) else {
17191717
return this.set_last_error_and_return_i32(LibcError("EBADF"));
17201718
};
@@ -1723,14 +1721,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
17231721
err_unsup_format!("`fchmod` is only supported on file-backed file descriptors")
17241722
})?;
17251723

1726-
let result = file.file.set_permissions(Permissions::from_mode(perm));
1724+
let result =
1725+
file.file.set_permissions(Permissions::from_mode(perm.try_into().unwrap()));
17271726
let result = this.try_unwrap_io_result(result.map(|_| 0i32))?;
17281727

17291728
interp_ok(Scalar::from_i32(result))
17301729
}
17311730
#[cfg(not(unix))]
17321731
{
1733-
unreachable!()
1732+
throw_unsup_format!("`fchmod` is not supported on this platform")
17341733
}
17351734
}
17361735
}

0 commit comments

Comments
 (0)