Merge remote branch 'jlee-r7/bug/rm7037-hash-iteration'

Hopefully I have the commit message hook right now.

[Fixes #39207979]
bug/bundler_fix
Tod Beardsley 2012-11-08 10:29:00 -06:00
commit c196cac398
4 changed files with 72 additions and 148 deletions

View File

@ -169,12 +169,14 @@ class Msf::ModuleSet < Hash
end
# @!attribute [rw] postpone_recalc
# Whether or not recalculations should be postponed. This is used from the context of the each_module_list
# handler in order to prevent the demand # loader from calling recalc for each module if it's possible that more
# than one module may be loaded. This field is not initialized until used.
# Whether or not recalculations should be postponed. This is used
# from the context of the {#each_module_list} handler in order to
# prevent the demand loader from calling recalc for each module if
# it's possible that more than one module may be loaded. This field
# is not initialized until used.
#
# @return [true] if recalculate should not be called immediately
# @return [false] if recalculate should be called immediately
# @return [true] if {#recalculate} should not be called immediately
# @return [false] if {#recalculate} should be called immediately
attr_accessor :postpone_recalculate
# Dummy placeholder to recalculate aliases and other fun things.
@ -217,10 +219,10 @@ class Msf::ModuleSet < Hash
# TODO this isn't terribly helpful since the refnames will always match, that's why they are ambiguous.
wlog("The module #{mod.refname} is ambiguous with #{self[name].refname}.")
else
self[name] = mod
end
self[name] = mod
mod
end

View File

@ -125,7 +125,7 @@ class Msf::Modules::Loader::Base
return false
end
loaded = namespace_module_transaction(type + "/" + module_reference_name, :reload => reload) { |namespace_module|
try_eval_module = lambda { |namespace_module|
# set the parent_path so that the module can be reloaded with #load_module
namespace_module.parent_path = parent_path
@ -173,29 +173,22 @@ class Msf::Modules::Loader::Base
return false
end
if reload
ilog("Reloading #{type} module #{module_reference_name}. Ambiguous module warnings are safe to ignore", 'core', LEV_2)
else
ilog("Loaded #{type} module #{module_reference_name} under #{parent_path}", 'core', LEV_2)
end
module_manager.module_load_error_by_path.delete(module_path)
true
}
loaded = namespace_module_transaction(type + "/" + module_reference_name, :reload => reload, &try_eval_module)
unless loaded
return false
end
if reload
# Delete the original copy of the module so that module_manager.on_load_module called from inside load_module does
# not trigger an ambiguous name warning, which would cause the reloaded module to not be stored in the
# ModuleManager.
module_manager.delete(module_reference_name)
# Delete the original copy of the module in the type-specific module set stores the reloaded module and doesn't
# trigger an ambiguous name warning
module_set = module_manager.module_set(type)
module_set.delete(module_reference_name)
end
# Do some processing on the loaded module to get it into the right associations
module_manager.on_module_load(
metasploit_class,

View File

@ -255,18 +255,27 @@ describe Msf::Modules::Loader::Base do
subject.stub(:module_path => module_path)
end
it 'should return false if :force is false and the file has not been changed' do
module_manager.stub(:file_changed? => false)
subject.load_module(parent_path, type, module_reference_name, :force => false).should be_false
end
it 'should call file_changed? with the module_path' do
module_manager.should_receive(:file_changed?).with(module_path).and_return(false)
subject.load_module(parent_path, type, module_reference_name, :force => false)
end
context 'without file changed' do
before(:each) do
module_manager.stub(:file_changed? => false)
end
it 'should return false if :force is false' do
subject.load_module(parent_path, type, module_reference_name, :force => false).should be_false
end
it 'should not call #read_module_content' do
subject.should_not_receive(:read_module_content)
subject.load_module(parent_path, type, module_reference_name)
end
end
context 'with file changed' do
let(:module_full_name) do
File.join('auxiliary', module_reference_name)
@ -621,87 +630,6 @@ describe Msf::Modules::Loader::Base do
subject.load_module(parent_path, type, module_reference_name).should be_true
end
context 'with module_reference_name already in module_manager' do
let(:framework) do
framework = mock('Framework', :datastore => {})
framework.stub_chain(:events, :on_module_load)
framework
end
let(:metasploit_class) do
@original_namespace_module::Metasploit3
end
let(:module_manager) do
Msf::ModuleManager.new(framework)
end
before(:each) do
# remove the stub from before(:each) in context 'with version compatibility'
module_manager.unstub(:on_module_load)
# remove the stubs from before(:each) in context 'with file changed'
module_manager.unstub(:delete)
module_manager.unstub(:module_set)
end
it 'should not cause an ambiguous module_reference_name in the module_manager' do
module_manager[module_reference_name] = metasploit_class
subject.load_module(parent_path, type, module_reference_name).should be_true
module_manager.send(:ambiguous_module_reference_name_set).should be_empty
end
it 'should not cause an ambiguous module_reference_name in the type module_set' do
module_set = module_manager.module_set(type)
module_set[module_reference_name] = metasploit_class
subject.load_module(parent_path, type, module_reference_name).should be_true
module_set.send(:ambiguous_module_reference_name_set).should be_empty
end
context 'without file changed' do
before(:each) do
module_manager.stub(:file_changed => false)
end
context 'with :force => true' do
it 'should not cause an ambiguous module_reference_name in the module_manager' do
module_manager[module_reference_name] = metasploit_class
subject.load_module(parent_path, type, module_reference_name, :force => true).should be_true
module_manager.send(:ambiguous_module_reference_name_set).should be_empty
end
it 'should not cause an ambiguous module_reference_name in the type module_set' do
module_set = module_manager.module_set(type)
module_set[module_reference_name] = metasploit_class
subject.load_module(parent_path, type, module_reference_name, :force => true).should be_true
module_set.send(:ambiguous_module_reference_name_set).should be_empty
end
end
context 'with :reload => true' do
it 'should not cause an ambiguous module_reference_name in the module_manager' do
module_manager[module_reference_name] = metasploit_class
subject.load_module(parent_path, type, module_reference_name, :reload => true).should be_true
module_manager.send(:ambiguous_module_reference_name_set).should be_empty
end
it 'should not cause an ambiguous module_reference_name in the type module_set' do
module_set = module_manager.module_set(type)
module_set[module_reference_name] = metasploit_class
subject.load_module(parent_path, type, module_reference_name, :reload => true).should be_true
module_set.send(:ambiguous_module_reference_name_set).should be_empty
end
end
end
end
it 'should call module_manager.on_module_load' do
module_manager.should_receive(:on_module_load)
subject.load_module(parent_path, type, module_reference_name).should be_true

View File

@ -1,4 +1,5 @@
shared_examples_for 'typed_path' do |map={}|
shared_examples_for 'typed_path' do |map|
map ||= {}
if map.length < 1
raise ArgumentError,
"type_path shared example requires a hash mapping the type constant name to the directory name: " \