Skip to content

Commit c946c25

Browse files
committed
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
2 parents 3244d53 + 0df68d8 commit c946c25

File tree

2 files changed

+12
-58
lines changed

2 files changed

+12
-58
lines changed

src/librustdoc/lib.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ pub fn opts() -> Vec<RustcOptGroup> {
165165
o.optmulti("", "extern", "pass an --extern to rustc", "NAME=PATH")
166166
}),
167167
stable("plugin-path", |o| {
168-
o.optmulti("", "plugin-path", "directory to load plugins from", "DIR")
168+
o.optmulti("", "plugin-path", "removed", "DIR")
169169
}),
170170
stable("C", |o| {
171171
o.optmulti("C", "codegen", "pass a codegen option to rustc", "OPT[=VALUE]")
@@ -178,7 +178,7 @@ pub fn opts() -> Vec<RustcOptGroup> {
178178
"PASSES")
179179
}),
180180
stable("plugins", |o| {
181-
o.optmulti("", "plugins", "space separated list of plugins to also load",
181+
o.optmulti("", "plugins", "removed",
182182
"PLUGINS")
183183
}),
184184
stable("no-default", |o| {
@@ -741,9 +741,16 @@ where R: 'static + Send,
741741
}
742742
}
743743

744+
if !plugins.is_empty() {
745+
eprintln!("WARNING: --plugins no longer functions; see CVE-2018-1000622");
746+
}
747+
748+
if !plugin_path.is_none() {
749+
eprintln!("WARNING: --plugin-path no longer functions; see CVE-2018-1000622");
750+
}
751+
744752
// Load all plugins/passes into a PluginManager
745-
let path = plugin_path.unwrap_or("/tmp/rustdoc/plugins".to_string());
746-
let mut pm = plugins::PluginManager::new(PathBuf::from(path));
753+
let mut pm = plugins::PluginManager::new();
747754
for pass in &passes {
748755
let plugin = match passes::PASSES.iter()
749756
.position(|&(p, ..)| {
@@ -757,10 +764,6 @@ where R: 'static + Send,
757764
};
758765
pm.add_plugin(plugin);
759766
}
760-
info!("loading plugins...");
761-
for pname in plugins {
762-
pm.load_plugin(pname);
763-
}
764767

765768
// Run everything!
766769
info!("Executing passes/plugins");
@@ -776,8 +779,6 @@ fn check_deprecated_options(matches: &getopts::Matches, diag: &errors::Handler)
776779
let deprecated_flags = [
777780
"input-format",
778781
"output-format",
779-
"plugin-path",
780-
"plugins",
781782
"no-defaults",
782783
"passes",
783784
];

src/librustdoc/plugins.rs

+1-48
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,20 @@
1212

1313
use clean;
1414

15-
use std::mem;
16-
use std::string::String;
17-
use std::path::PathBuf;
18-
19-
use rustc_metadata::dynamic_lib as dl;
20-
2115
pub type PluginResult = clean::Crate;
2216
pub type PluginCallback = fn (clean::Crate) -> PluginResult;
2317

2418
/// Manages loading and running of plugins
2519
pub struct PluginManager {
26-
dylibs: Vec<dl::DynamicLibrary> ,
2720
callbacks: Vec<PluginCallback> ,
28-
/// The directory plugins will be loaded from
29-
pub prefix: PathBuf,
3021
}
3122

3223
impl PluginManager {
3324
/// Create a new plugin manager
34-
pub fn new(prefix: PathBuf) -> PluginManager {
25+
pub fn new() -> PluginManager {
3526
PluginManager {
36-
dylibs: Vec::new(),
3727
callbacks: Vec::new(),
38-
prefix,
39-
}
40-
}
41-
42-
/// Load a plugin with the given name.
43-
///
44-
/// Turns `name` into the proper dynamic library filename for the given
45-
/// platform. On windows, it turns into name.dll, on macOS, name.dylib, and
46-
/// elsewhere, libname.so.
47-
pub fn load_plugin(&mut self, name: String) {
48-
let x = self.prefix.join(libname(name));
49-
let lib_result = dl::DynamicLibrary::open(Some(&x));
50-
let lib = lib_result.unwrap();
51-
unsafe {
52-
let plugin = lib.symbol("rustdoc_plugin_entrypoint").unwrap();
53-
self.callbacks.push(mem::transmute::<*mut u8,PluginCallback>(plugin));
5428
}
55-
self.dylibs.push(lib);
5629
}
5730

5831
/// Load a normal Rust function as a plugin.
@@ -70,23 +43,3 @@ impl PluginManager {
7043
krate
7144
}
7245
}
73-
74-
#[cfg(target_os = "windows")]
75-
fn libname(mut n: String) -> String {
76-
n.push_str(".dll");
77-
n
78-
}
79-
80-
#[cfg(target_os="macos")]
81-
fn libname(mut n: String) -> String {
82-
n.push_str(".dylib");
83-
n
84-
}
85-
86-
#[cfg(all(not(target_os="windows"), not(target_os="macos")))]
87-
fn libname(n: String) -> String {
88-
let mut i = String::from("lib");
89-
i.push_str(&n);
90-
i.push_str(".so");
91-
i
92-
}

0 commit comments

Comments
 (0)