From d1e50d618c942d299bac724d5c4e28c128ab4661 Mon Sep 17 00:00:00 2001 From: tiif Date: Sun, 5 Jan 2025 02:01:50 +0800 Subject: [PATCH] Add check for other variadic functions --- src/shims/unix/android/thread.rs | 1 + src/shims/unix/foreign_items.rs | 1 + src/shims/unix/linux_like/syscall.rs | 1 + 3 files changed, 3 insertions(+) diff --git a/src/shims/unix/android/thread.rs b/src/shims/unix/android/thread.rs index 8d5d4a52b6..bdcc97bb85 100644 --- a/src/shims/unix/android/thread.rs +++ b/src/shims/unix/android/thread.rs @@ -19,6 +19,7 @@ pub fn prctl<'tcx>( // We do not use `check_shim` here because `prctl` is variadic. The argument // count is checked bellow. ecx.check_abi_and_shim_symbol_clash(abi, Conv::C, link_name)?; + ecx.check_fixed_args_count("prctl", abi, 1)?; // FIXME: Use constants once https://github.com/rust-lang/libc/pull/3941 backported to the 0.2 branch. let pr_set_name = 15; diff --git a/src/shims/unix/foreign_items.rs b/src/shims/unix/foreign_items.rs index 0c0ae748d4..a868e651e6 100644 --- a/src/shims/unix/foreign_items.rs +++ b/src/shims/unix/foreign_items.rs @@ -208,6 +208,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // `fcntl` is variadic. The argument count is checked based on the first argument // in `this.fcntl()`, so we do not use `check_shim` here. this.check_abi_and_shim_symbol_clash(abi, Conv::C , link_name)?; + this.check_fixed_args_count("fcntl", abi, 2)?; let result = this.fcntl(args)?; this.write_scalar(result, dest)?; } diff --git a/src/shims/unix/linux_like/syscall.rs b/src/shims/unix/linux_like/syscall.rs index 5fb262e176..d74af2d8bb 100644 --- a/src/shims/unix/linux_like/syscall.rs +++ b/src/shims/unix/linux_like/syscall.rs @@ -17,6 +17,7 @@ pub fn syscall<'tcx>( // We do not use `check_shim` here because `syscall` is variadic. The argument // count is checked bellow. ecx.check_abi_and_shim_symbol_clash(abi, Conv::C, link_name)?; + ecx.check_fixed_args_count("syscall", abi, 1)?; // The syscall variadic function is legal to call with more arguments than needed, // extra arguments are simply ignored. The important check is that when we use an // argument, we have to also check all arguments *before* it to ensure that they