3 ms·
This does seem to be the case. Here is an example I was able to create: use std::io::stdin; fn main() { let mut s = String::new(); stdin().rea
by Paul-ish 8y ago
This does seem to be the case. Here is an example I was able to create:
use std::io::stdin;
fn main() {
let mut s = String::new();
stdin().read_line(&mut s).expect("Did not enter a correct string");
let sql_example = format!("SELECT * FROM users WHERE username={}", s);
let x = Box::new(sql_example);
let static_ref: &'static str = Box::leak(x);
println!("{}", static_ref)
}
Note the type on our variable "static_ref". It is a static str, meaning it could be an argument to the code in the blog post. No "unsafe" blocks either.
When I run it
Input: ' OR '1'='1
Output: SELECT * FROM users WHERE username=' OR '1'='1
The technique might be still useful if it was only allowed in debug builds to reduce boilerplate during debugging in a system that tried to use types to solve the issue.