Last active: 9 months ago
rust memory vulnerability
fn main() {
let mut safety = &String::from("hello");
println!("address of safety {:p}: {}", &safety, safety);
{
let name = "xfy".to_string();
let name = expand(&name);
println!("address of name {:p}: {}", &name, name);
safety = &name;
}
println!("address of safety {:p}: {}", &safety, safety);
}
pub const fn lifetime_translator<'a, 'b, T>(_val_a: &'a &'b (), _val_b: &'b T) -> &'a T {
_val_b
}
pub fn lifetime_translator_mut<'a, 'b, T>(_val_a: &'a &'b (), _val_b: &'b mut T) -> &'a mut T {
_val_b
}
pub fn expand<'a, 'b, T>(x: &'a T) -> &'b T {
// lifetime_translator(STATIC_UNIT, x)
let f: fn(_, &'a T) -> &'b T = lifetime_translator;
f(STATIC_UNIT, x)
}
pub fn expand_mut<'a, 'b, T>(x: &'a mut T) -> &'b mut T {
let f: fn(_, &'a mut T) -> &'b mut T = lifetime_translator_mut;
f(STATIC_UNIT, x)
}
const STATIC_UNIT: &&() = &&();