2 ms·
If I'm reading the blog code correctly, the error is trusting user input: // Rust let len = buffer[0] as usize; // C size_t len = buffer[0]; I
by pacala 12y ago
If I'm reading the blog code correctly, the error is trusting user input:
// Rust
let len = buffer[0] as usize;
// C
size_t len = buffer[0];
I'm no Rust hacker, but can I expect the Rust type system to be able to encode some form of tainting? Making the leaky sequence illegal:
let len = buffer[0] as usize;
// ERROR ERROR ERROR using unscrubbed user input ERROR ERROR ERROR
buffer[0 .. len]
How exactly to encode tainting is left as an exercise to the reader :) But ideally it should be able to identify that the buffer is reused between 2 different requests, and that data tainted from second request is used to index an array tainted with data from first request. This seems eery up Rust's alley, given the concurrency / allocation disambiguation support I've read (alas superficially) elsewhere.
- kibwen 12y agoYou can absolutely express tainting via the type system. I have seen this done before in Rust code in order to express functions that can only accept strings that have been properly sanitized, along with a function that takes an unsanitized string and returns a sanitized one. This particular example was using phantom types, though you could obviously also define wholly separate types for this sort of thing.