Skip to content

Commit 7f839a0

Browse files
committed
Land rapid7#7825, don't double-load plugins
2 parents 56ed8bc + 0800a4f commit 7f839a0

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

lib/msf/core/plugin_manager.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ def load(path, opts = {})
6868
Kernel.load(path + ".rb")
6969
end
7070

71+
# Force unloading if already loaded
72+
plugin = self.find { |p| p.class == klass }
73+
unload(plugin) if plugin
74+
7175
# Create an instance of the plugin and let it initialize
7276
instance = klass.create(framework, opts)
7377

lib/msf/core/rpc/v10/rpc_plugin.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,16 @@ def rpc_load(path, xopts = {})
5757
# @example Here's how you would use this from the client:
5858
# rpc.call('plugin.unload', 'nexpose')
5959
def rpc_unload(name)
60-
self.framework.plugins.each { |plugin|
61-
# Unload the plugin if it matches the name we're searching for
62-
if (plugin.name == name)
63-
self.framework.plugins.unload(plugin)
64-
return { "result" => "success" }
65-
end
66-
}
67-
return { "result" => "failure" }
60+
# Find a plugin within the plugins array
61+
plugin = self.framework.plugins.find { |p| p.name == name }
6862

63+
# Unload the plugin if it matches the name we're searching for
64+
if plugin
65+
self.framework.plugins.unload(plugin)
66+
return { "result" => "success" }
67+
end
68+
69+
return { "result" => "failure" }
6970
end
7071

7172

lib/msf/ui/console/command_dispatcher/core.rb

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,16 +1653,15 @@ def cmd_unload(*args)
16531653
return false
16541654
end
16551655

1656-
# Walk the plugins array
1657-
framework.plugins.each { |plugin|
1658-
# Unload the plugin if it matches the name we're searching for
1659-
if (plugin.name.downcase == args[0].downcase)
1660-
print("Unloading plugin #{args[0]}...")
1661-
framework.plugins.unload(plugin)
1662-
print_line("unloaded.")
1663-
break
1664-
end
1665-
}
1656+
# Find a plugin within the plugins array
1657+
plugin = framework.plugins.find { |p| p.name.downcase == args[0].downcase }
1658+
1659+
# Unload the plugin if it matches the name we're searching for
1660+
if plugin
1661+
print("Unloading plugin #{args[0]}...")
1662+
framework.plugins.unload(plugin)
1663+
print_line("unloaded.")
1664+
end
16661665
end
16671666

16681667
#

0 commit comments

Comments
 (0)