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.
This commit is contained in:
parent
8ae5a55ba5
commit
dfdb017a9b
2 changed files with 50 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
// Helper functions used only in tests
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
|
@ -415,3 +416,14 @@ rust_dbg_unpack_option_u64u64(struct U8TaggedEnumOptionU64U64 o, uint64_t *a, ui
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t issue_97463_leak_uninit_data(uint32_t a, uint32_t b, uint32_t c) {
|
||||
struct bloc { uint16_t a; uint16_t b; uint16_t c; };
|
||||
struct bloc *data = malloc(sizeof(struct bloc));
|
||||
|
||||
data->a = a & 0xFFFF;
|
||||
data->b = b & 0xFFFF;
|
||||
data->c = c & 0xFFFF;
|
||||
|
||||
return data->b; /* leak data */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
// run-pass
|
||||
#![allow(dead_code)]
|
||||
#![allow(improper_ctypes)]
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern "C" {
|
||||
pub fn issue_97463_leak_uninit_data(a: u32, b: u32, c: u32) -> u16;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
const C1: usize = 0x327b23c6;
|
||||
const C2: usize = C1 & 0xFFFF;
|
||||
|
||||
let r1: usize = 0x0;
|
||||
let r2: usize = C1;
|
||||
let r3: usize = 0x0;
|
||||
let value: u16 = unsafe { issue_97463_leak_uninit_data(r1 as u32, r2 as u32, r3 as u32) };
|
||||
|
||||
// NOTE: as an example of the sensitivity of this test to optimization choices,
|
||||
// uncommenting this block of code makes the bug go away on pnkfeix's machine.
|
||||
// (But observing via `dbg!` doesn't hide the bug. At least sometimes.)
|
||||
/*
|
||||
println!("{}", value);
|
||||
println!("{}", value as usize);
|
||||
println!("{}", usize::from(value));
|
||||
println!("{}", (value as usize) & 0xFFFF);
|
||||
*/
|
||||
|
||||
let d1 = value;
|
||||
let d2 = value as usize;
|
||||
let d3 = usize::from(value);
|
||||
let d4 = (value as usize) & 0xFFFF;
|
||||
|
||||
let d = (&d1, &d2, &d3, &d4);
|
||||
let d_ = (d1, d2, d3, d4);
|
||||
|
||||
assert_eq!(((&(C2 as u16), &C2, &C2, &C2), (C2 as u16, C2, C2, C2)), (d, d_));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue