-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix 'LocalRequest::clone()' soundness issue.
The existing implementation of 'LocalRequest::clone()' mistakenly copied the internal 'Request' pointer from the existing 'LocalRequest' to the cloned 'LocalRequest'. This resulted in an aliased '*mut Request' pointer, a clear soundness issue. The fix in this commit is to clone the internal 'Request', replacing the internal pointer with the newly cloned 'Request' when producing the cloned 'LocalRequest'. A fix that removes all 'unsafe' code should be explored. Fixes #1312.
- Loading branch information
1 parent
ccb5eb1
commit 89150f9
Showing
2 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
extern crate rocket; | ||
|
||
use rocket::http::Header; | ||
use rocket::local::Client; | ||
|
||
#[test] | ||
fn test_local_request_clone_soundness() { | ||
let client = Client::new(rocket::ignite()).unwrap(); | ||
|
||
// creates two LocalRequest instances that shouldn't share the same req | ||
let r1 = client.get("/").header(Header::new("key", "val1")); | ||
let mut r2 = r1.clone(); | ||
|
||
// save the iterator, which internally holds a slice | ||
let mut iter = r1.inner().headers().get("key"); | ||
|
||
// insert headers to force header map reallocation. | ||
for i in 0..100 { | ||
r2.add_header(Header::new(i.to_string(), i.to_string())); | ||
} | ||
|
||
// Replace the original key/val. | ||
r2.add_header(Header::new("key", "val2")); | ||
|
||
// Heap massage: so we've got crud to print. | ||
let _: Vec<usize> = vec![0, 0xcafebabe, 31337, 0]; | ||
|
||
// Ensure we're good. | ||
let s = iter.next().unwrap(); | ||
println!("{}", s); | ||
|
||
// And that we've got the right data. | ||
assert_eq!(r1.inner().headers().get("key").collect::<Vec<_>>(), vec!["val1"]); | ||
assert_eq!(r2.inner().headers().get("key").collect::<Vec<_>>(), vec!["val1", "val2"]); | ||
} |