Skip to content

Commit dfdb017

Browse files
committed
experiment: trying to encode the end-to-end test as a ui test via rust_test_helpers. This instance is almost certainly insufficient because we need to force optimization flags for both the C and Rust sides of the code. but lets find out for sure.
1 parent 8ae5a55 commit dfdb017

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/test/auxiliary/rust_test_helpers.c

+12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Helper functions used only in tests
22

33
#include <stdint.h>
4+
#include <stdlib.h>
45
#include <assert.h>
56
#include <stdarg.h>
67

@@ -415,3 +416,14 @@ rust_dbg_unpack_option_u64u64(struct U8TaggedEnumOptionU64U64 o, uint64_t *a, ui
415416
return 0;
416417
}
417418
}
419+
420+
uint16_t issue_97463_leak_uninit_data(uint32_t a, uint32_t b, uint32_t c) {
421+
struct bloc { uint16_t a; uint16_t b; uint16_t c; };
422+
struct bloc *data = malloc(sizeof(struct bloc));
423+
424+
data->a = a & 0xFFFF;
425+
data->b = b & 0xFFFF;
426+
data->c = c & 0xFFFF;
427+
428+
return data->b; /* leak data */
429+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// run-pass
2+
#![allow(dead_code)]
3+
#![allow(improper_ctypes)]
4+
5+
#[link(name = "rust_test_helpers", kind = "static")]
6+
extern "C" {
7+
pub fn issue_97463_leak_uninit_data(a: u32, b: u32, c: u32) -> u16;
8+
}
9+
10+
fn main() {
11+
const C1: usize = 0x327b23c6;
12+
const C2: usize = C1 & 0xFFFF;
13+
14+
let r1: usize = 0x0;
15+
let r2: usize = C1;
16+
let r3: usize = 0x0;
17+
let value: u16 = unsafe { issue_97463_leak_uninit_data(r1 as u32, r2 as u32, r3 as u32) };
18+
19+
// NOTE: as an example of the sensitivity of this test to optimization choices,
20+
// uncommenting this block of code makes the bug go away on pnkfeix's machine.
21+
// (But observing via `dbg!` doesn't hide the bug. At least sometimes.)
22+
/*
23+
println!("{}", value);
24+
println!("{}", value as usize);
25+
println!("{}", usize::from(value));
26+
println!("{}", (value as usize) & 0xFFFF);
27+
*/
28+
29+
let d1 = value;
30+
let d2 = value as usize;
31+
let d3 = usize::from(value);
32+
let d4 = (value as usize) & 0xFFFF;
33+
34+
let d = (&d1, &d2, &d3, &d4);
35+
let d_ = (d1, d2, d3, d4);
36+
37+
assert_eq!(((&(C2 as u16), &C2, &C2, &C2), (C2 as u16, C2, C2, C2)), (d, d_));
38+
}

0 commit comments

Comments
 (0)