Skip to content

Commit 653c71e

Browse files
committed
Fail if init_module_paths called more than once
MSP-11672 Calling init_module_paths takes 6 seconds on my machine even when there are no files to that are changed just because it takes that long to walk the directories and gather the mtime for each file. Therefore, calling it more than once should be avoided. Also, there is no reason to call it twice as to add paths later, `modules.add_module_paths` should be used.
1 parent 394d132 commit 653c71e

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

lib/msf/base/simple/framework/module_paths.rb

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,32 @@ module ModulePaths
77
#
88
# @return [void]
99
def init_module_paths(opts={})
10-
# Ensure the module cache is accurate
11-
self.modules.refresh_cache_from_database
10+
if @module_paths_inited
11+
fail "Module paths already initialized. To add more module paths call `modules.add_module_path`"
12+
else
13+
# Ensure the module cache is accurate
14+
self.modules.refresh_cache_from_database
1215

13-
add_engine_module_paths(Rails.application, opts)
16+
add_engine_module_paths(Rails.application, opts)
1417

15-
Rails.application.railties.engines.each do |engine|
16-
add_engine_module_paths(engine, opts)
17-
end
18+
Rails.application.railties.engines.each do |engine|
19+
add_engine_module_paths(engine, opts)
20+
end
1821

19-
# Initialize the user module search path
20-
if (Msf::Config.user_module_directory)
21-
self.modules.add_module_path(Msf::Config.user_module_directory, opts)
22-
end
22+
# Initialize the user module search path
23+
if (Msf::Config.user_module_directory)
24+
self.modules.add_module_path(Msf::Config.user_module_directory, opts)
25+
end
26+
27+
# If additional module paths have been defined globally, then load them.
28+
# They should be separated by semi-colons.
29+
if self.datastore['MsfModulePaths']
30+
self.datastore['MsfModulePaths'].split(";").each { |path|
31+
self.modules.add_module_path(path, opts)
32+
}
33+
end
2334

24-
# If additional module paths have been defined globally, then load them.
25-
# They should be separated by semi-colons.
26-
if self.datastore['MsfModulePaths']
27-
self.datastore['MsfModulePaths'].split(";").each { |path|
28-
self.modules.add_module_path(path, opts)
29-
}
35+
@module_paths_inited = true
3036
end
3137
end
3238

0 commit comments

Comments
 (0)