Skip to content

Commit 070c3d9

Browse files
committed
Fix UI tests for invalid POSIX function definitions
1 parent f8aecf5 commit 070c3d9

8 files changed

Lines changed: 31 additions & 28 deletions

File tree

tests/ui/abi/stack-protector.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#![allow(function_casts_as_integer)]
1010

1111
use std::env;
12+
use std::ffi::c_void;
1213
use std::process::{Command, ExitStatus};
1314

1415
fn main() {
@@ -42,7 +43,9 @@ fn vulnerable_function() {
4243
let bad_code_ptr = malicious_code as usize;
4344
// Overwrite the on-stack return address with the address of `malicious_code()`,
4445
// thereby jumping to that function when returning from `vulnerable_function()`.
45-
unsafe { fill(stackaddr, bad_code_ptr, 20); }
46+
unsafe {
47+
fill(stackaddr, bad_code_ptr, 20);
48+
}
4649
// Capture the address, so the write is not optimized away.
4750
std::hint::black_box(stackaddr);
4851
}
@@ -68,16 +71,15 @@ unsafe fn fill(addr: *mut usize, val: usize, count: usize) {
6871
fn malicious_code() {
6972
let msg = [112u8, 119u8, 110u8, 101u8, 100u8, 33u8, 0u8]; // "pwned!\0" ascii
7073
unsafe {
71-
write(1, &msg as *const u8, msg.len());
74+
write(1, &msg as *const u8 as *const c_void, msg.len());
7275
_exit(0);
7376
}
7477
}
7578
extern "C" {
76-
fn write(fd: i32, buf: *const u8, count: usize) -> isize;
79+
fn write(fd: i32, buf: *const c_void, count: usize) -> isize;
7780
fn _exit(status: i32) -> !;
7881
}
7982

80-
8183
fn assert_stack_smash_prevented(cmd: &mut Command) {
8284
let (status, stdout, stderr) = run(cmd);
8385
assert!(!status.success());
@@ -92,7 +94,6 @@ fn assert_stack_smashed(cmd: &mut Command) {
9294
assert!(stderr.is_empty());
9395
}
9496

95-
9697
fn run(cmd: &mut Command) -> (ExitStatus, String, String) {
9798
let output = cmd.output().unwrap();
9899
let stdout = String::from_utf8_lossy(&output.stdout);

tests/ui/cfg/conditional-compile.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ struct r {
4747

4848
#[cfg(false)]
4949
fn r(i: isize) -> r {
50-
r { i: i }
50+
r { i }
5151
}
5252

5353
struct r {
5454
i: isize,
5555
}
5656

5757
fn r(i: isize) -> r {
58-
r { i: i }
58+
r { i }
5959
}
6060

6161
#[cfg(false)]
@@ -111,8 +111,8 @@ mod test_foreign_items {
111111
pub mod rustrt {
112112
extern "C" {
113113
#[cfg(false)]
114-
pub fn write() -> String;
115-
pub fn write() -> String;
114+
pub fn foo() -> String;
115+
pub fn foo() -> String;
116116
}
117117
}
118118
}

tests/ui/extern/extern-pub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ run-pass
22

33
extern "C" {
4-
pub fn free(p: *const u8);
4+
pub fn free(p: *mut std::ffi::c_void);
55
}
66

77
pub fn main() {}

tests/ui/ffi/ffi-struct-size-alignment.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// Incorrect struct size computation in the FFI, because of not taking
66
// the alignment of elements into account.
77

8-
98
use std::ffi::{c_uint, c_void};
109

1110
pub struct KEYGEN {
@@ -17,7 +16,7 @@ pub struct KEYGEN {
1716

1817
extern "C" {
1918
// Bogus signature, just need to test if it compiles.
20-
pub fn malloc(data: KEYGEN);
19+
pub fn foo(data: KEYGEN);
2120
}
2221

2322
pub fn main() {}

tests/ui/lint/dead-code/lint-dead-code-3.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,28 @@ mod blah {
4848
enum c_void {}
4949

5050
extern "C" {
51-
fn free(p: *const c_void);
52-
fn malloc(size: usize) -> *const c_void;
51+
fn my_free(p: *const c_void);
52+
fn my_malloc(size: usize) -> *const c_void;
5353
}
5454

5555
pub fn baz() {
56-
unsafe { free(malloc(4)); }
56+
unsafe {
57+
my_free(my_malloc(4));
58+
}
5759
}
5860
}
5961

6062
enum c_void {} //~ ERROR: enum `c_void` is never used
6163
extern "C" {
62-
fn free(p: *const c_void); //~ ERROR: function `free` is never used
64+
fn my_free(p: *const c_void); //~ ERROR: function `my_free` is never used
6365
}
6466

6567
// Check provided method
6668
mod inner {
6769
pub trait Trait {
68-
fn f(&self) { f(); }
70+
fn f(&self) {
71+
f();
72+
}
6973
}
7074

7175
impl Trait for isize {}

tests/ui/lint/dead-code/lint-dead-code-3.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,28 @@ LL | fn bar() {
2525
| ^^^
2626

2727
error: enum `c_void` is never used
28-
--> $DIR/lint-dead-code-3.rs:60:6
28+
--> $DIR/lint-dead-code-3.rs:62:6
2929
|
3030
LL | enum c_void {}
3131
| ^^^^^^
3232

3333
error: function `blah` is never used
34-
--> $DIR/lint-dead-code-3.rs:77:8
34+
--> $DIR/lint-dead-code-3.rs:81:8
3535
|
3636
LL | fn blah() {}
3737
| ^^^^
3838

3939
error: function `blah` is never used
40-
--> $DIR/lint-dead-code-3.rs:81:12
40+
--> $DIR/lint-dead-code-3.rs:85:12
4141
|
4242
LL | fn blah() {}
4343
| ^^^^
4444

45-
error: function `free` is never used
46-
--> $DIR/lint-dead-code-3.rs:62:8
45+
error: function `my_free` is never used
46+
--> $DIR/lint-dead-code-3.rs:64:8
4747
|
48-
LL | fn free(p: *const c_void);
49-
| ^^^^
48+
LL | fn my_free(p: *const c_void);
49+
| ^^^^^^^
5050

5151
error: aborting due to 7 previous errors
5252

tests/ui/lint/warn-ctypes-inhibit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//@ run-pass
2-
3-
#![allow(dead_code)]
42
//@ compile-flags:-D improper-ctypes
53

4+
#![allow(dead_code)]
65
#![allow(improper_ctypes)]
6+
#![allow(suspicious_runtime_symbol_definitions)]
77

88
mod libc {
99
extern "C" {

tests/ui/privacy/pub-extern-privacy.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
//@ run-pass
22

3-
43
use std::mem::transmute;
54

65
mod a {
76
extern "C" {
8-
pub fn free(x: *const u8);
7+
pub fn free(x: *mut std::ffi::c_void);
98
}
109
}
1110

0 commit comments

Comments
 (0)