Skip to content

Commit 809d0f7

Browse files
author
Brent Cook
committed
Land rapid7#9026, Fix cache invalidation bug in tab completion
2 parents b7e209a + 403b5e2 commit 809d0f7

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,9 @@ def commands
139139
def initialize(driver)
140140
super
141141

142-
@dscache = {}
143142
@cache_payloads = nil
144143
@previous_module = nil
145-
@module_name_stack = []
144+
@previous_target = nil
146145
@history_limit = 100
147146
end
148147

@@ -1627,12 +1626,6 @@ def cmd_set(*args)
16271626
# Set the supplied name to the supplied value
16281627
name = args[0]
16291628
value = args[1, args.length-1].join(' ')
1630-
if (name.upcase == "TARGET")
1631-
# Different targets can have different architectures and platforms
1632-
# so we need to rebuild the payload list whenever the target
1633-
# changes.
1634-
@cache_payloads = nil
1635-
end
16361629

16371630
# If the driver indicates that the value is not valid, bust out.
16381631
if (driver.on_variable_set(global, name, value) == false)
@@ -2288,11 +2281,16 @@ def option_values_dispatch(o, str, words)
22882281
# Provide valid payload options for the current exploit
22892282
#
22902283
def option_values_payloads
2291-
return @cache_payloads if @cache_payloads
2284+
if @cache_payloads && active_module == @previous_module && active_module.target == @previous_target
2285+
return @cache_payloads
2286+
end
2287+
2288+
@previous_module = active_module
2289+
@previous_target = active_module.target
22922290

2293-
@cache_payloads = active_module.compatible_payloads.map { |refname, payload|
2291+
@cache_payloads = active_module.compatible_payloads.map do |refname, payload|
22942292
refname
2295-
}
2293+
end
22962294

22972295
@cache_payloads
22982296
end

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def initialize(driver)
4848
super
4949

5050
@dscache = {}
51-
@cache_payloads = nil
5251
@previous_module = nil
5352
@module_name_stack = []
5453
@dangerzone_map = nil
@@ -645,7 +644,6 @@ def cmd_use(*args)
645644
active_module.datastore.update(@dscache[active_module.fullname])
646645
end
647646

648-
@cache_payloads = nil
649647
mod.init_ui(driver.input, driver.output)
650648

651649
# Update the command prompt

0 commit comments

Comments
 (0)