Auto merge of #52194 - steveklabnik:remove-plugins, r=QuietMisdreavus,GuillaumeGomez
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
This commit is contained in:
commit
c946c2539e
2 changed files with 12 additions and 58 deletions
|
@ -165,7 +165,7 @@ pub fn opts() -> Vec<RustcOptGroup> {
|
||||||
o.optmulti("", "extern", "pass an --extern to rustc", "NAME=PATH")
|
o.optmulti("", "extern", "pass an --extern to rustc", "NAME=PATH")
|
||||||
}),
|
}),
|
||||||
stable("plugin-path", |o| {
|
stable("plugin-path", |o| {
|
||||||
o.optmulti("", "plugin-path", "directory to load plugins from", "DIR")
|
o.optmulti("", "plugin-path", "removed", "DIR")
|
||||||
}),
|
}),
|
||||||
stable("C", |o| {
|
stable("C", |o| {
|
||||||
o.optmulti("C", "codegen", "pass a codegen option to rustc", "OPT[=VALUE]")
|
o.optmulti("C", "codegen", "pass a codegen option to rustc", "OPT[=VALUE]")
|
||||||
|
@ -178,7 +178,7 @@ pub fn opts() -> Vec<RustcOptGroup> {
|
||||||
"PASSES")
|
"PASSES")
|
||||||
}),
|
}),
|
||||||
stable("plugins", |o| {
|
stable("plugins", |o| {
|
||||||
o.optmulti("", "plugins", "space separated list of plugins to also load",
|
o.optmulti("", "plugins", "removed",
|
||||||
"PLUGINS")
|
"PLUGINS")
|
||||||
}),
|
}),
|
||||||
stable("no-default", |o| {
|
stable("no-default", |o| {
|
||||||
|
@ -741,9 +741,16 @@ where R: 'static + Send,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
// Load all plugins/passes into a PluginManager
|
||||||
let path = plugin_path.unwrap_or("/tmp/rustdoc/plugins".to_string());
|
let mut pm = plugins::PluginManager::new();
|
||||||
let mut pm = plugins::PluginManager::new(PathBuf::from(path));
|
|
||||||
for pass in &passes {
|
for pass in &passes {
|
||||||
let plugin = match passes::PASSES.iter()
|
let plugin = match passes::PASSES.iter()
|
||||||
.position(|&(p, ..)| {
|
.position(|&(p, ..)| {
|
||||||
|
@ -757,10 +764,6 @@ where R: 'static + Send,
|
||||||
};
|
};
|
||||||
pm.add_plugin(plugin);
|
pm.add_plugin(plugin);
|
||||||
}
|
}
|
||||||
info!("loading plugins...");
|
|
||||||
for pname in plugins {
|
|
||||||
pm.load_plugin(pname);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run everything!
|
// Run everything!
|
||||||
info!("Executing passes/plugins");
|
info!("Executing passes/plugins");
|
||||||
|
@ -776,8 +779,6 @@ fn check_deprecated_options(matches: &getopts::Matches, diag: &errors::Handler)
|
||||||
let deprecated_flags = [
|
let deprecated_flags = [
|
||||||
"input-format",
|
"input-format",
|
||||||
"output-format",
|
"output-format",
|
||||||
"plugin-path",
|
|
||||||
"plugins",
|
|
||||||
"no-defaults",
|
"no-defaults",
|
||||||
"passes",
|
"passes",
|
||||||
];
|
];
|
||||||
|
|
|
@ -12,49 +12,22 @@
|
||||||
|
|
||||||
use clean;
|
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 PluginResult = clean::Crate;
|
||||||
pub type PluginCallback = fn (clean::Crate) -> PluginResult;
|
pub type PluginCallback = fn (clean::Crate) -> PluginResult;
|
||||||
|
|
||||||
/// Manages loading and running of plugins
|
/// Manages loading and running of plugins
|
||||||
pub struct PluginManager {
|
pub struct PluginManager {
|
||||||
dylibs: Vec<dl::DynamicLibrary> ,
|
|
||||||
callbacks: Vec<PluginCallback> ,
|
callbacks: Vec<PluginCallback> ,
|
||||||
/// The directory plugins will be loaded from
|
|
||||||
pub prefix: PathBuf,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PluginManager {
|
impl PluginManager {
|
||||||
/// Create a new plugin manager
|
/// Create a new plugin manager
|
||||||
pub fn new(prefix: PathBuf) -> PluginManager {
|
pub fn new() -> PluginManager {
|
||||||
PluginManager {
|
PluginManager {
|
||||||
dylibs: Vec::new(),
|
|
||||||
callbacks: 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.
|
/// Load a normal Rust function as a plugin.
|
||||||
///
|
///
|
||||||
/// This is to run passes over the cleaned crate. Plugins run this way
|
/// This is to run passes over the cleaned crate. Plugins run this way
|
||||||
|
@ -70,23 +43,3 @@ impl PluginManager {
|
||||||
krate
|
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
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue