22
33use std:: borrow:: Cow ;
44use std:: fs:: {
5- DirBuilder , File , FileType , Metadata , OpenOptions , Permissions , ReadDir , read_dir, remove_dir,
6- remove_file , rename,
5+ DirBuilder , File , FileType , Metadata , OpenOptions , ReadDir , read_dir, remove_dir, remove_file ,
6+ rename,
77} ;
88use std:: io:: { self , ErrorKind , IsTerminal , Read , Seek , SeekFrom , Write } ;
99use std:: path:: { Path , PathBuf } ;
@@ -1668,9 +1668,6 @@ 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- 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-
16741671 // Reject if isolation is enabled.
16751672 if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
16761673 this. reject_in_isolation ( "`chmod`" , reject_with) ?;
@@ -1680,8 +1677,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
16801677 // Permissions::from_mode is Unix-specific.
16811678 #[ cfg( unix) ]
16821679 {
1680+ use std:: fs:: Permissions ;
16831681 use std:: os:: unix:: fs:: PermissionsExt ;
16841682
1683+ let pathname = this. read_path_from_c_str ( this. read_pointer ( path_op) ?) ?;
1684+ let perm = this. read_scalar ( perm_op) ?. to_uint ( this. libc_ty_layout ( "mode_t" ) . size ) ?;
1685+
16851686 let result = std:: fs:: set_permissions (
16861687 pathname,
16871688 Permissions :: from_mode ( perm. try_into ( ) . unwrap ( ) ) ,
@@ -1692,27 +1693,30 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
16921693 }
16931694 #[ cfg( not( unix) ) ]
16941695 {
1696+ let ( _, _) = ( fd_op, perm_op) ;
16951697 throw_unsup_format ! ( "`chmod` is not supported on this platform" )
16961698 }
16971699 }
16981700
16991701 fn fchmod ( & mut self , fd_op : & OpTy < ' tcx > , perm_op : & OpTy < ' tcx > ) -> InterpResult < ' tcx , Scalar > {
17001702 let this = self . eval_context_mut ( ) ;
17011703
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 ) ?;
1704-
17051704 // Reject if isolation is enabled.
17061705 if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
17071706 this. reject_in_isolation ( "`fchmod`" , reject_with) ?;
17081707 // Set error code as "EBADF" (bad fd)
17091708 return this. set_last_error_and_return_i32 ( LibcError ( "EBADF" ) ) ;
17101709 }
1710+
17111711 // `Permissions::from_mode` is Unix-specific.
17121712 #[ cfg( unix) ]
17131713 {
1714+ use std:: fs:: Permissions ;
17141715 use std:: os:: unix:: fs:: PermissionsExt ;
17151716
1717+ let fd = this. read_scalar ( fd_op) ?. to_i32 ( ) ?;
1718+ let perm = this. read_scalar ( perm_op) ?. to_uint ( this. libc_ty_layout ( "mode_t" ) . size ) ?;
1719+
17161720 let Some ( fd) = this. machine . fds . get ( fd) else {
17171721 return this. set_last_error_and_return_i32 ( LibcError ( "EBADF" ) ) ;
17181722 } ;
@@ -1729,6 +1733,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
17291733 }
17301734 #[ cfg( not( unix) ) ]
17311735 {
1736+ let ( _, _) = ( fd_op, perm_op) ;
17321737 throw_unsup_format ! ( "`fchmod` is not supported on this platform" )
17331738 }
17341739 }
0 commit comments