Skip to content

Commit

Permalink
fix memory corruption in geyser plugin manager tests with recent tool…
Browse files Browse the repository at this point in the history
…chains (solana-labs#33097)

* geyser: genericize manager test dummy plugin generators

* geyser: dlopen self the safe way in test dummy plugin generator

fixes memory corruption
  • Loading branch information
t-nelson authored Aug 31, 2023
1 parent d146056 commit 7e5cd11
Showing 1 changed file with 14 additions and 26 deletions.
40 changes: 14 additions & 26 deletions geyser-plugin-manager/src/geyser_plugin_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ pub(crate) fn load_plugin_from_config(
pub(crate) fn load_plugin_from_config(
_geyser_plugin_config_file: &Path,
) -> Result<(Box<dyn GeyserPlugin>, Library, &str), GeyserPluginManagerError> {
Ok(tests::dummy_plugin_and_library())
Ok(tests::dummy_plugin_and_library(tests::TestPlugin))
}

#[cfg(test)]
Expand All @@ -345,33 +345,21 @@ mod tests {
std::sync::{Arc, RwLock},
};

pub(super) fn dummy_plugin_and_library() -> (Box<dyn GeyserPlugin>, Library, &'static str) {
let plugin = Box::new(TestPlugin);
let lib = {
let handle: *mut std::os::raw::c_void = &mut () as *mut _ as *mut std::os::raw::c_void;
// SAFETY: all calls to get Symbols should fail, so this is actually safe
let inner_lib = unsafe { libloading::os::unix::Library::from_raw(handle) };
Library::from(inner_lib)
};
(plugin, lib, DUMMY_CONFIG)
}

pub(super) fn dummy_plugin_and_library2() -> (Box<dyn GeyserPlugin>, Library, &'static str) {
let plugin = Box::new(TestPlugin2);
let lib = {
let handle: *mut std::os::raw::c_void = &mut () as *mut _ as *mut std::os::raw::c_void;
// SAFETY: all calls to get Symbols should fail, so this is actually safe
let inner_lib = unsafe { libloading::os::unix::Library::from_raw(handle) };
Library::from(inner_lib)
};
(plugin, lib, DUMMY_CONFIG)
pub(super) fn dummy_plugin_and_library<P: GeyserPlugin>(
plugin: P,
) -> (Box<dyn GeyserPlugin>, Library, &'static str) {
(
Box::new(plugin),
Library::from(libloading::os::unix::Library::this()),
DUMMY_CONFIG,
)
}

const DUMMY_NAME: &str = "dummy";
pub(super) const DUMMY_CONFIG: &str = "dummy_config";
const ANOTHER_DUMMY_NAME: &str = "another_dummy";

#[derive(Debug)]
#[derive(Clone, Copy, Debug)]
pub(super) struct TestPlugin;

impl GeyserPlugin for TestPlugin {
Expand All @@ -380,7 +368,7 @@ mod tests {
}
}

#[derive(Debug)]
#[derive(Clone, Copy, Debug)]
pub(super) struct TestPlugin2;

impl GeyserPlugin for TestPlugin2 {
Expand All @@ -403,7 +391,7 @@ mod tests {
);

// Mock having loaded plugin (TestPlugin)
let (mut plugin, lib, config) = dummy_plugin_and_library();
let (mut plugin, lib, config) = dummy_plugin_and_library(TestPlugin);
plugin.on_load(config).unwrap();
plugin_manager_lock.plugins.push(plugin);
plugin_manager_lock.libs.push(lib);
Expand Down Expand Up @@ -432,12 +420,12 @@ mod tests {

// Load two plugins
// First
let (mut plugin, lib, config) = dummy_plugin_and_library();
let (mut plugin, lib, config) = dummy_plugin_and_library(TestPlugin);
plugin.on_load(config).unwrap();
plugin_manager_lock.plugins.push(plugin);
plugin_manager_lock.libs.push(lib);
// Second
let (mut plugin, lib, config) = dummy_plugin_and_library2();
let (mut plugin, lib, config) = dummy_plugin_and_library(TestPlugin2);
plugin.on_load(config).unwrap();
plugin_manager_lock.plugins.push(plugin);
plugin_manager_lock.libs.push(lib);
Expand Down

0 comments on commit 7e5cd11

Please sign in to comment.