Skip to content

Commit 01f6461

Browse files
committed
Check that the only flag change is done to enable FD_CLOEXEC
1 parent 3726081 commit 01f6461

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/shims/io.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
6969
let cmd = this.read_scalar(cmd_op)?.to_i32()?;
7070

7171
if cmd == this.eval_libc_i32("F_SETFD")? {
72+
// This does not affect the file itself. Certain flags might require changing the file
73+
// or the way it is accessed somehow.
7274
let flag = this.read_scalar(arg_op.unwrap())?.to_i32()?;
73-
this.machine.file_handler.flags.insert(fd, flag);
75+
// The only usage of this in stdlib at the moment is to enable the `FD_CLOEXEC` flag.
76+
let fd_cloexec = this.eval_libc_i32("FD_CLOEXEC")?;
77+
if let Some(old_flag) = this.machine.file_handler.flags.get_mut(&fd) {
78+
if flag ^ *old_flag == fd_cloexec {
79+
*old_flag = flag;
80+
} else {
81+
throw_unsup_format!("Unsupported arg {:#x} for `F_SETFD`", flag);
82+
}
83+
}
7484
Ok(0)
7585
} else if cmd == this.eval_libc_i32("F_GETFD")? {
7686
if let Some(flag) = this.machine.file_handler.flags.get(&fd) {

0 commit comments

Comments
 (0)