]> git.lizzy.rs Git - rust.git/commitdiff
make sure we check argument count everywhere
authorRalf Jung <post@ralfj.de>
Tue, 5 May 2020 09:57:08 +0000 (11:57 +0200)
committerRalf Jung <post@ralfj.de>
Tue, 5 May 2020 09:59:22 +0000 (11:59 +0200)
src/shims/foreign_items/posix.rs
src/shims/foreign_items/windows.rs
src/shims/intrinsics.rs

index 6b28e7070165bc31e736d63bd045e12c02d7eaca..a68414ddbc2fe7668ea25c5276acadff186c6690 100644 (file)
@@ -379,19 +379,8 @@ fn emulate_foreign_item_by_name(
 
             // Incomplete shims that we "stub out" just to get pre-main initialization code to work.
             // These shims are enabled only when the caller is in the standard library.
-            | "pthread_attr_init"
-            | "pthread_attr_destroy"
-            | "pthread_attr_setstacksize"
-            | "pthread_condattr_init"
-            | "pthread_condattr_setclock"
-            | "pthread_cond_init"
-            | "pthread_condattr_destroy"
-            | "pthread_cond_destroy" if this.frame().instance.to_string().starts_with("std::sys::unix::")
-            => {
-                this.write_null(dest)?;
-            }
-            "pthread_attr_getguardsize" if this.frame().instance.to_string().starts_with("std::sys::unix::")
-            => {
+            "pthread_attr_getguardsize"
+            if this.frame().instance.to_string().starts_with("std::sys::unix::") => {
                 let &[_attr, guard_size] = check_arg_count(args)?;
                 let guard_size = this.deref_operand(guard_size)?;
                 let guard_size_layout = this.libc_ty_layout("size_t")?;
@@ -401,11 +390,33 @@ fn emulate_foreign_item_by_name(
                 this.write_null(dest)?;
             }
 
+            | "pthread_attr_init"
+            | "pthread_attr_destroy"
+            | "pthread_condattr_init"
+            | "pthread_condattr_destroy"
+            | "pthread_cond_destroy"
+            if this.frame().instance.to_string().starts_with("std::sys::unix::") => {
+                let &[_] = check_arg_count(args)?;
+                this.write_null(dest)?;
+            }
+            | "pthread_cond_init"
+            | "pthread_attr_setstacksize"
+            | "pthread_condattr_setclock"
+            if this.frame().instance.to_string().starts_with("std::sys::unix::") => {
+                let &[_, _] = check_arg_count(args)?;
+                this.write_null(dest)?;
+            }
+
             | "signal"
-            | "sigaction"
             | "sigaltstack"
-            | "mprotect" if this.frame().instance.to_string().starts_with("std::sys::unix::")
-            => {
+            if this.frame().instance.to_string().starts_with("std::sys::unix::") => {
+                let &[_, _] = check_arg_count(args)?;
+                this.write_null(dest)?;
+            }
+            | "sigaction"
+            | "mprotect"
+            if this.frame().instance.to_string().starts_with("std::sys::unix::") => {
+                let &[_, _, _] = check_arg_count(args)?;
                 this.write_null(dest)?;
             }
 
index ab912476f6a93df79104b7513df61d0ba51af6ec..cff1887ff8b54327f7a090abb83bb284b0addc37 100644 (file)
@@ -251,22 +251,19 @@ fn emulate_foreign_item_by_name(
                 // Just fake a HANDLE
                 this.write_scalar(Scalar::from_machine_isize(1, this), dest)?;
             }
-            "GetModuleHandleW" if this.frame().instance.to_string().starts_with("std::sys::windows::")
-            => {
+            "GetModuleHandleW" if this.frame().instance.to_string().starts_with("std::sys::windows::") => {
                 #[allow(non_snake_case)]
                 let &[_lpModuleName] = check_arg_count(args)?;
                 // Pretend this does not exist / nothing happened, by returning zero.
                 this.write_null(dest)?;
             }
-            "GetProcAddress" if this.frame().instance.to_string().starts_with("std::sys::windows::")
-            => {
+            "GetProcAddress" if this.frame().instance.to_string().starts_with("std::sys::windows::") => {
                 #[allow(non_snake_case)]
                 let &[_hModule, _lpProcName] = check_arg_count(args)?;
                 // Pretend this does not exist / nothing happened, by returning zero.
                 this.write_null(dest)?;
             }
-            "SetConsoleTextAttribute" if this.frame().instance.to_string().starts_with("std::sys::windows::")
-            => {
+            "SetConsoleTextAttribute" if this.frame().instance.to_string().starts_with("std::sys::windows::") => {
                 #[allow(non_snake_case)]
                 let &[_hConsoleOutput, _wAttribute] = check_arg_count(args)?;
                 // Pretend these does not exist / nothing happened, by returning zero.
@@ -281,8 +278,8 @@ fn emulate_foreign_item_by_name(
             | "InitializeCriticalSection"
             | "EnterCriticalSection"
             | "LeaveCriticalSection"
-            | "DeleteCriticalSection" if this.frame().instance.to_string().starts_with("std::sys::windows::")
-            => {
+            | "DeleteCriticalSection"
+            if this.frame().instance.to_string().starts_with("std::sys::windows::") => {
                 #[allow(non_snake_case)]
                 let &[_lpCriticalSection] = check_arg_count(args)?;
                 assert_eq!(this.get_total_thread_count()?, 1, "concurrency on Windows not supported");
@@ -290,8 +287,8 @@ fn emulate_foreign_item_by_name(
                 // (Windows locks are reentrant, and we have only 1 thread,
                 // so not doing any futher checks here is at least not incorrect.)
             }
-            "TryEnterCriticalSection" if this.frame().instance.to_string().starts_with("std::sys::windows::")
-            => {
+            "TryEnterCriticalSection"
+            if this.frame().instance.to_string().starts_with("std::sys::windows::") => {
                 #[allow(non_snake_case)]
                 let &[_lpCriticalSection] = check_arg_count(args)?;
                 assert_eq!(this.get_total_thread_count()?, 1, "concurrency on Windows not supported");
index a77443ef52247cf185a5faf67f7933fe55f8a388..cf485b5477468d20a7c3b36f5cf44daccb92fae0 100644 (file)
@@ -363,6 +363,7 @@ fn call_intrinsic(
             | "atomic_singlethreadfence_acqrel"
             | "atomic_singlethreadfence"
             => {
+                let &[] = check_arg_count(args)?;
                 // we are inherently singlethreaded and singlecored, this is a nop
             }