Skip to content

Commit c03ff13

Browse files
committed
Don't wait if the response has already been set
Fixes a race condition which could leave the waiter sitting indefinitely if notify() is called before wait().
1 parent 12b24fe commit c03ff13

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/rex/post/meterpreter/packet_response_waiter.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ def waiting_for?(packet)
4444
# Notifies the waiter that the supplied response packet has arrived.
4545
#
4646
def notify(response)
47-
self.response = response
48-
4947
if (self.completion_routine)
48+
self.response = response
5049
self.completion_routine.call(response, self.completion_param)
5150
else
52-
self.mutex.synchronize {
51+
self.mutex.synchronize do
52+
self.response = response
5353
self.cond.signal
54-
}
54+
end
5555
end
5656
end
5757

@@ -61,9 +61,11 @@ def notify(response)
6161
#
6262
def wait(interval)
6363
interval = nil if interval and interval == -1
64-
self.mutex.synchronize {
65-
self.cond.wait(self.mutex, interval)
66-
}
64+
self.mutex.synchronize do
65+
if self.response.nil?
66+
self.cond.wait(self.mutex, interval)
67+
end
68+
end
6769
return self.response
6870
end
6971

0 commit comments

Comments
 (0)