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 ( ) ) ,
@@ -1699,20 +1700,22 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
16991700 fn fchmod ( & mut self , fd_op : & OpTy < ' tcx > , perm_op : & OpTy < ' tcx > ) -> InterpResult < ' tcx , Scalar > {
17001701 let this = self . eval_context_mut ( ) ;
17011702
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-
17051703 // Reject if isolation is enabled.
17061704 if let IsolatedOp :: Reject ( reject_with) = this. machine . isolated_op {
17071705 this. reject_in_isolation ( "`fchmod`" , reject_with) ?;
17081706 // Set error code as "EBADF" (bad fd)
17091707 return this. set_last_error_and_return_i32 ( LibcError ( "EBADF" ) ) ;
17101708 }
1709+
17111710 // `Permissions::from_mode` is Unix-specific.
17121711 #[ cfg( unix) ]
17131712 {
1713+ use std:: fs:: Permissions ;
17141714 use std:: os:: unix:: fs:: PermissionsExt ;
17151715
1716+ let fd = this. read_scalar ( fd_op) ?. to_i32 ( ) ?;
1717+ let perm = this. read_scalar ( perm_op) ?. to_uint ( this. libc_ty_layout ( "mode_t" ) . size ) ?;
1718+
17161719 let Some ( fd) = this. machine . fds . get ( fd) else {
17171720 return this. set_last_error_and_return_i32 ( LibcError ( "EBADF" ) ) ;
17181721 } ;
0 commit comments