Skip to content

Commit 39d0117

Browse files
committed
Move deletion into #remove_resource
Doing it here means that modules manually calling remove_resource won't screw up the cleanup
1 parent e8a92eb commit 39d0117

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/msf/core/exploit/http/server.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def initialize(info = {})
3636
], Exploit::Remote::HttpServer
3737
)
3838

39+
# Used to keep track of resources added to the service manager by
40+
# this module. see #add_resource and #cleanup
3941
@my_resources = []
4042
@service_path = nil
4143
end
@@ -205,9 +207,8 @@ def start_service(opts = {})
205207

206208
# Take care of removing any resources that we created
207209
def cleanup
208-
@my_resources.delete_if do |resource|
210+
@my_resources.each do |resource|
209211
remove_resource(resource)
210-
true
211212
end
212213

213214
super
@@ -374,7 +375,8 @@ def add_resource(opts)
374375
@service_path = opts['Path']
375376
res = service.add_resource(opts['Path'], opts)
376377

377-
# This has to go *after* the call to add_resource in case it raises
378+
# This has to go *after* the call to service.add_resource in case
379+
# the service manager doesn't like it for some reason and raises.
378380
@my_resources.push(opts['Path'])
379381

380382
res
@@ -472,7 +474,11 @@ def srvhost_addr
472474
# Removes a URI resource.
473475
#
474476
def remove_resource(name)
475-
service.remove_resource(name)
477+
# Guard against removing resources added by other modules
478+
if @my_resources.include?(name)
479+
@my_resources.delete(name)
480+
service.remove_resource(name)
481+
end
476482
end
477483

478484
#

0 commit comments

Comments
 (0)