Skip to content

Commit b40c366

Browse files
author
Brent Cook
committed
check send retry count and abort in excess
1 parent 6e14679 commit b40c366

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/rex/proto/tftp/client.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ def send_data(host,port)
295295
end
296296
sent_data = 0
297297
sent_blocks = 0
298+
send_retries = 0
298299
expected_blocks = data_blocks.size
299300
expected_size = data_blocks.join.size
300301
if block_given?
@@ -304,7 +305,15 @@ def send_data(host,port)
304305
data_blocks.each_with_index do |data_block,idx|
305306
loop do
306307
req = [OpData, (idx + 1), data_block].pack("nnA*")
307-
self.server_sock.sendto(req, host, port)
308+
if self.server_sock.sendto(req, host, port) <= 0
309+
send_retries += 1
310+
if send_retries > 100
311+
break
312+
else
313+
next
314+
end
315+
end
316+
send_retries = 0
308317
res = self.server_sock.recvfrom(65535)
309318
if res
310319
code, type, msg = parse_tftp_response(res[0])
@@ -326,13 +335,19 @@ def send_data(host,port)
326335
end
327336
end
328337
end
338+
339+
if send_retries > 100
340+
yield "Too many send retries, aborted"
341+
end
342+
329343
if block_given?
330344
if(sent_data == expected_size)
331345
yield("Transferred #{sent_data} bytes in #{sent_blocks} blocks, upload complete!")
332346
else
333347
yield "Upload complete, but with errors."
334348
end
335349
end
350+
336351
if sent_data == expected_size
337352
self.status = {:success => [
338353
self.local_file,

0 commit comments

Comments
 (0)