Skip to content

Commit 10dafcd

Browse files
egypttodb
authored andcommitted
Fix 1.8 compat with Module#const_defined?
Before 1.9, const_defined? only takes one parameter.
1 parent 95fef5d commit 10dafcd

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

lib/msf/core/modules/loader/base.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,14 @@ def create_namespace_module(namespace_module_names)
370370
# @return [Module] module that wraps the previously loaded content from {#read_module_content}.
371371
# @return [nil] if any module name along the chain does not exist.
372372
def current_module(module_names)
373-
# don't look at ancestors for constant
374-
inherit = false
375-
376373
# Don't want to trigger ActiveSupport's const_missing, so can't use constantize.
377374
named_module = module_names.inject(Object) { |parent, module_name|
378-
if parent.const_defined?(module_name, inherit)
379-
parent.const_get(module_name, inherit)
375+
# Since we're searching parent namespaces first anyway, this is
376+
# semantically equivalent to providing false for the 1.9-only
377+
# "inherit" parameter to const_defined?. If we ever drop 1.8
378+
# support, we can save a few cycles here by adding it back.
379+
if parent.const_defined?(module_name)
380+
parent.const_get(module_name)
380381
else
381382
break
382383
end
@@ -617,4 +618,4 @@ def usable?(metasploit_class)
617618

618619
usable
619620
end
620-
end
621+
end

lib/msf/core/modules/namespace.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ module Msf::Modules::Namespace
1111
def metasploit_class
1212
metasploit_class = nil
1313
# don't search ancestors for the metasploit_class
14-
inherit = false
14+
#inherit = false
1515

1616
::Msf::Framework::Major.downto(1) do |major|
17-
if const_defined?("Metasploit#{major}", inherit)
17+
# Since we really only care about the deepest namespace, we don't
18+
# need to look for parents' constants. However, the "inherit"
19+
# parameter for const_defined? only exists after 1.9. If we ever
20+
# drop 1.8 support, we can save a few cycles here by passing false
21+
# here.
22+
if const_defined?("Metasploit#{major}")
1823
metasploit_class = const_get("Metasploit#{major}")
1924

2025
break
@@ -52,4 +57,4 @@ def version_compatible!(module_path, module_reference_name)
5257
end
5358
end
5459
end
55-
end
60+
end

0 commit comments

Comments
 (0)