Skip to content

Instantly share code, notes, and snippets.

@vi vi/
Last active Jan 17, 2016

What would you like to do?
Crashing Safe Rust code with OS help
// This code demonstrates that with OS's external help
// one can crash even Safe Rust's code
// Implemented by Vitaly "_Vi" Shukela
use std::process::Command;
fn getpid() -> i32 {
let so = Command::new("sh")
.arg("cat /proc/$$/status | grep PPid: | awk '{print $2}'")
fn hacky_ptr_write<T>(pointer: &T, value: u32) {
.arg("-pid").arg(format!("{}", getpid()))
.arg(format!("set {{unsigned long}}{:p} = {}", pointer, value))
fn main() {
let mut q = &mut Box::new(55);
hacky_ptr_write(&q, 0);
*q = Box::new(44); // SEGV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.