Skip to content

Commit 8a7dbde

Browse files
author
Vytautas Astrauskas
committed
Check prctl argument types and fix the test.
1 parent 40e50bf commit 8a7dbde

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/shims/thread.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,26 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
9292
&mut self,
9393
option: OpTy<'tcx, Tag>,
9494
arg2: OpTy<'tcx, Tag>,
95-
_arg3: OpTy<'tcx, Tag>,
96-
_arg4: OpTy<'tcx, Tag>,
97-
_arg5: OpTy<'tcx, Tag>,
95+
arg3: OpTy<'tcx, Tag>,
96+
arg4: OpTy<'tcx, Tag>,
97+
arg5: OpTy<'tcx, Tag>,
9898
) -> InterpResult<'tcx, i32> {
9999
let this = self.eval_context_mut();
100100

101+
// prctl last 5 arguments are declared as variadic. Therefore, we need
102+
// to check their types manually.
103+
let c_long_size = this.libc_ty_layout("c_long")?.size.bytes();
104+
let check_arg = |arg: OpTy<'tcx, Tag>| -> InterpResult<'tcx> {
105+
match this.read_scalar(arg)?.not_undef()? {
106+
Scalar::Raw { size, .. } if u64::from(size) == c_long_size => Ok(()),
107+
_ => throw_ub_format!("an argument of unsupported type was passed to prctl"),
108+
}
109+
};
110+
check_arg(arg2)?;
111+
check_arg(arg3)?;
112+
check_arg(arg4)?;
113+
check_arg(arg5)?;
114+
101115
let option = this.read_scalar(option)?.not_undef()?.to_i32()?;
102116
if option == this.eval_libc_i32("PR_SET_NAME")? {
103117
let address = this.read_scalar(arg2)?.not_undef()?;

tests/run-pass/concurrency/libc_prctl_thread_name.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use std::ffi::CString;
99
fn main() {
1010
unsafe {
1111
let thread_name = CString::new("hello").expect("CString::new failed");
12-
assert_eq!(libc::prctl(libc::PR_SET_NAME, thread_name.as_ptr() as u64, 0, 0, 0), 0);
12+
assert_eq!(libc::prctl(libc::PR_SET_NAME, thread_name.as_ptr() as libc::c_long, 0 as libc::c_long, 0 as libc::c_long, 0 as libc::c_long), 0);
1313
let mut buf = [0; 6];
14-
assert_eq!(libc::prctl(libc::PR_GET_NAME, buf.as_mut_ptr() as u64, 0, 0, 0), 0);
14+
assert_eq!(libc::prctl(libc::PR_GET_NAME, buf.as_mut_ptr() as libc::c_long, 0 as libc::c_long, 0 as libc::c_long, 0 as libc::c_long), 0);
1515
assert_eq!(thread_name.as_bytes_with_nul(), buf);
1616
}
1717
}

0 commit comments

Comments
 (0)