]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #52194 - steveklabnik:remove-plugins, r=QuietMisdreavus,GuillaumeGomez
authorbors <bors@rust-lang.org>
Thu, 12 Jul 2018 04:12:19 +0000 (04:12 +0000)
committerbors <bors@rust-lang.org>
Thu, 12 Jul 2018 04:12:19 +0000 (04:12 +0000)
Remove rustdoc's plugins feature

This fixes CVE-2018-1000622.

https://cve.mitre.org/cgi-bin/cvename.cgi?name=%20CVE-2018-1000622

r? @QuietMisdreavus @GuillaumeGomez

src/librustdoc/lib.rs
src/librustdoc/plugins.rs

index 5f4739bd22276ac10247e3871a43664d573ac8fd..3e26ed2b97c23c893bb05f1f0857076a2e230c7f 100644 (file)
@@ -165,7 +165,7 @@ pub fn opts() -> Vec<RustcOptGroup> {
             o.optmulti("", "extern", "pass an --extern to rustc", "NAME=PATH")
         }),
         stable("plugin-path", |o| {
-            o.optmulti("", "plugin-path", "directory to load plugins from", "DIR")
+            o.optmulti("", "plugin-path", "removed", "DIR")
         }),
         stable("C", |o| {
             o.optmulti("C", "codegen", "pass a codegen option to rustc", "OPT[=VALUE]")
@@ -178,7 +178,7 @@ pub fn opts() -> Vec<RustcOptGroup> {
                        "PASSES")
         }),
         stable("plugins", |o| {
-            o.optmulti("", "plugins", "space separated list of plugins to also load",
+            o.optmulti("", "plugins", "removed",
                        "PLUGINS")
         }),
         stable("no-default", |o| {
@@ -741,9 +741,16 @@ fn report_deprecated_attr(name: &str, diag: &errors::Handler) {
             }
         }
 
+        if !plugins.is_empty() {
+            eprintln!("WARNING: --plugins no longer functions; see CVE-2018-1000622");
+        }
+
+        if !plugin_path.is_none() {
+            eprintln!("WARNING: --plugin-path no longer functions; see CVE-2018-1000622");
+        }
+
         // Load all plugins/passes into a PluginManager
-        let path = plugin_path.unwrap_or("/tmp/rustdoc/plugins".to_string());
-        let mut pm = plugins::PluginManager::new(PathBuf::from(path));
+        let mut pm = plugins::PluginManager::new();
         for pass in &passes {
             let plugin = match passes::PASSES.iter()
                                              .position(|&(p, ..)| {
@@ -757,10 +764,6 @@ fn report_deprecated_attr(name: &str, diag: &errors::Handler) {
             };
             pm.add_plugin(plugin);
         }
-        info!("loading plugins...");
-        for pname in plugins {
-            pm.load_plugin(pname);
-        }
 
         // Run everything!
         info!("Executing passes/plugins");
@@ -776,8 +779,6 @@ fn check_deprecated_options(matches: &getopts::Matches, diag: &errors::Handler)
     let deprecated_flags = [
        "input-format",
        "output-format",
-       "plugin-path",
-       "plugins",
        "no-defaults",
        "passes",
     ];
index 1a1e60a6945edd2fc26bb7e3c8a7fbe5292aec89..261ff728aef605aabe41a2a10cbc50134c1271f5 100644 (file)
 
 use clean;
 
-use std::mem;
-use std::string::String;
-use std::path::PathBuf;
-
-use rustc_metadata::dynamic_lib as dl;
-
 pub type PluginResult = clean::Crate;
 pub type PluginCallback = fn (clean::Crate) -> PluginResult;
 
 /// Manages loading and running of plugins
 pub struct PluginManager {
-    dylibs: Vec<dl::DynamicLibrary> ,
     callbacks: Vec<PluginCallback> ,
-    /// The directory plugins will be loaded from
-    pub prefix: PathBuf,
 }
 
 impl PluginManager {
     /// Create a new plugin manager
-    pub fn new(prefix: PathBuf) -> PluginManager {
+    pub fn new() -> PluginManager {
         PluginManager {
-            dylibs: Vec::new(),
             callbacks: Vec::new(),
-            prefix,
-        }
-    }
-
-    /// Load a plugin with the given name.
-    ///
-    /// Turns `name` into the proper dynamic library filename for the given
-    /// platform. On windows, it turns into name.dll, on macOS, name.dylib, and
-    /// elsewhere, libname.so.
-    pub fn load_plugin(&mut self, name: String) {
-        let x = self.prefix.join(libname(name));
-        let lib_result = dl::DynamicLibrary::open(Some(&x));
-        let lib = lib_result.unwrap();
-        unsafe {
-            let plugin = lib.symbol("rustdoc_plugin_entrypoint").unwrap();
-            self.callbacks.push(mem::transmute::<*mut u8,PluginCallback>(plugin));
         }
-        self.dylibs.push(lib);
     }
 
     /// Load a normal Rust function as a plugin.
@@ -70,23 +43,3 @@ pub fn run_plugins(&self, mut krate: clean::Crate) -> clean::Crate {
         krate
     }
 }
-
-#[cfg(target_os = "windows")]
-fn libname(mut n: String) -> String {
-    n.push_str(".dll");
-    n
-}
-
-#[cfg(target_os="macos")]
-fn libname(mut n: String) -> String {
-    n.push_str(".dylib");
-    n
-}
-
-#[cfg(all(not(target_os="windows"), not(target_os="macos")))]
-fn libname(n: String) -> String {
-    let mut i = String::from("lib");
-    i.push_str(&n);
-    i.push_str(".so");
-    i
-}