Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aarch64 call abi does not zeroext (and one cannot assume it does so) #97800

Merged
Prev Previous commit
Next Next commit
experiment: trying to encode the end-to-end test as a ui test via rus…
…t_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.
  • Loading branch information
pnkfelix committed Jul 6, 2022
commit dfdb017a9bb6284f58ff8447cd2a49c778552f62
12 changes: 12 additions & 0 deletions src/test/auxiliary/rust_test_helpers.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Helper functions used only in tests

#include <stdint.h>
#include <stdlib.h>
#include <assert.h>
#include <stdarg.h>

Expand Down Expand Up @@ -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 */
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// run-pass
wesleywiser marked this conversation as resolved.
Show resolved Hide resolved
#![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.
bjorn3 marked this conversation as resolved.
Show resolved Hide resolved
// (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_));
}