diff options
author | Simon Sapin <simon.sapin@exyr.org> | 2016-04-21 00:18:37 +0200 |
---|---|---|
committer | Simon Sapin <simon.sapin@exyr.org> | 2016-04-23 20:27:58 +0200 |
commit | 7932ab6ac2646e097a2ef2f76d6e4439fe53bdd3 (patch) | |
tree | d486c090f3287be1036f2aea0f544b65ec95d43e /components/net/chrome_loader.rs | |
parent | 305c283602882850be9d39c43b980d0fc0f93a3c (diff) | |
download | servo-7932ab6ac2646e097a2ef2f76d6e4439fe53bdd3.tar.gz servo-7932ab6ac2646e097a2ef2f76d6e4439fe53bdd3.zip |
Upgrade to rust-url 1.0 and hyper 0.9
Diffstat (limited to 'components/net/chrome_loader.rs')
-rw-r--r-- | components/net/chrome_loader.rs | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/components/net/chrome_loader.rs b/components/net/chrome_loader.rs index f18792de021..07367ce5367 100644 --- a/components/net/chrome_loader.rs +++ b/components/net/chrome_loader.rs @@ -6,26 +6,21 @@ use file_loader; use mime_classifier::MIMEClassifier; use net_traits::{LoadConsumer, LoadData, NetworkError}; use resource_thread::{CancellationListener, send_error}; -use std::path::Path; use std::sync::Arc; use url::Url; use util::resource_files::resources_dir_path; pub fn resolve_chrome_url(url: &Url) -> Result<Url, ()> { - assert_eq!(url.scheme, "chrome"); - // Skip the initial // - let non_relative_scheme_data = &url.non_relative_scheme_data().unwrap()[2..]; - let relative_path = Path::new(non_relative_scheme_data); + assert_eq!(url.scheme(), "chrome"); + let resources = resources_dir_path(); + let mut path = resources.clone(); + for segment in url.path_segments().unwrap() { + path.push(segment) + } // Don't allow chrome URLs access to files outside of the resources directory. - if non_relative_scheme_data.find("..").is_some() || - relative_path.is_absolute() || - relative_path.has_root() { + if !(path.starts_with(resources) && path.exists()) { return Err(()); } - - let mut path = resources_dir_path(); - path.push(non_relative_scheme_data); - assert!(path.exists()); return Ok(Url::from_file_path(&*path).unwrap()); } |