Closed
Description
Simplest reproduction.
extern crate httparse;
use httparse::{EMPTY_HEADER, parse_headers};
fn main() {
let mut buf = *b"Foo: Bar\r\n\r\n";
let mut headers = [EMPTY_HEADER];
let headers_len = {
let (_, headers) = parse_headers(&mut buf, &mut headers).unwrap().unwrap();
headers.len()
} ;
assert_eq!(headers_len, 1);
buf[0] = b'B';
// Prints "Boo"
println!("{:?}", headers[0].name);
}
As you can see, parse_headers()
allows borrows to buf
to escape in headers
, creating a double-borrow where the original buffer can be mutated while views to it exist.
Discovered by accident, I was working on some infinite-loop bugs in multipart when I took a double-take at this function and thought, "Wait a minute, how the hell did this work to begin with?" The r.consume()
at 80 shouldn't be allowed, but the borrow is escaping.
Metadata
Metadata
Assignees
Labels
No labels