ruby-changes:39475
From: nagachika <ko1@a...>
Date: Thu, 13 Aug 2015 01:40:29 +0900 (JST)
Subject: [ruby-changes:39475] nagachika:r51556 (ruby_2_2): merge revision(s) 51046: [Backport #11260]
nagachika 2015-08-13 01:40:08 +0900 (Thu, 13 Aug 2015) New Revision: 51556 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51556 Log: merge revision(s) 51046: [Backport #11260] * lib/net/ftp.rb (makeport): close the TCPServer when sending the port fails. * test/net/ftp/test_ftp.rb: test for above. Modified directories: branches/ruby_2_2/ Modified files: branches/ruby_2_2/ChangeLog branches/ruby_2_2/lib/net/ftp.rb branches/ruby_2_2/test/net/ftp/test_ftp.rb branches/ruby_2_2/version.h Index: ruby_2_2/ChangeLog =================================================================== --- ruby_2_2/ChangeLog (revision 51555) +++ ruby_2_2/ChangeLog (revision 51556) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ChangeLog#L1 +Thu Aug 13 01:25:26 2015 Benoit Daloze <eregontp@g...> + + * lib/net/ftp.rb (makeport): close the TCPServer + when sending the port fails. + + * test/net/ftp/test_ftp.rb: test for above. + Thu Aug 13 01:03:13 2015 Kazuki Tsujimoto <kazuki@c...> * lib/net/http/response.rb (Net::HTTPResponse::Inflater#finish): Index: ruby_2_2/lib/net/ftp.rb =================================================================== --- ruby_2_2/lib/net/ftp.rb (revision 51555) +++ ruby_2_2/lib/net/ftp.rb (revision 51556) @@ -377,15 +377,9 @@ module Net https://github.com/ruby/ruby/blob/trunk/ruby_2_2/lib/net/ftp.rb#L377 end private :sendport - # Constructs a TCPServer socket, and sends it the PORT command - # - # Returns the constructed TCPServer socket + # Constructs a TCPServer socket def makeport # :nodoc: - sock = TCPServer.open(@sock.addr[3], 0) - port = sock.addr[1] - host = sock.addr[3] - sendport(host, port) - return sock + TCPServer.open(@sock.addr[3], 0) end private :makeport @@ -421,6 +415,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/ruby_2_2/lib/net/ftp.rb#L415 else sock = makeport begin + sendport(sock.addr[3], sock.addr[1]) if @resume and rest_offset resp = sendcmd("REST " + rest_offset.to_s) if resp[0] != ?3 Index: ruby_2_2/version.h =================================================================== --- ruby_2_2/version.h (revision 51555) +++ ruby_2_2/version.h (revision 51556) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1 #define RUBY_VERSION "2.2.3" #define RUBY_RELEASE_DATE "2015-08-13" -#define RUBY_PATCHLEVEL 162 +#define RUBY_PATCHLEVEL 163 #define RUBY_RELEASE_YEAR 2015 #define RUBY_RELEASE_MONTH 8 Index: ruby_2_2/test/net/ftp/test_ftp.rb =================================================================== --- ruby_2_2/test/net/ftp/test_ftp.rb (revision 51555) +++ ruby_2_2/test/net/ftp/test_ftp.rb (revision 51556) @@ -469,6 +469,46 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/net/ftp/test_ftp.rb#L469 end end + def test_open_data_port_fail_no_leak + commands = [] + server = create_ftp_server { |sock| + sock.print("220 (test_ftp).\r\n") + commands.push(sock.gets) + sock.print("331 Please specify the password.\r\n") + commands.push(sock.gets) + sock.print("230 Login successful.\r\n") + commands.push(sock.gets) + sock.print("200 Switching to Binary mode.\r\n") + commands.push(sock.gets) + sock.print("200 Switching to ASCII mode.\r\n") + line = sock.gets + commands.push(line) + sock.print("421 Service not available, closing control connection.\r\n") + commands.push(sock.gets) + sock.print("200 Switching to Binary mode.\r\n") + } + begin + begin + ftp = Net::FTP.new + ftp.read_timeout = 0.2 + ftp.connect(SERVER_ADDR, server.port) + ftp.login + assert_match(/\AUSER /, commands.shift) + assert_match(/\APASS /, commands.shift) + assert_equal("TYPE I\r\n", commands.shift) + assert_raise(Net::FTPTempError){ ftp.list } + assert_equal("TYPE A\r\n", commands.shift) + assert_match(/\APORT /, commands.shift) + assert_equal("TYPE I\r\n", commands.shift) + assert_equal(nil, commands.shift) + ensure + ftp.close if ftp + end + ensure + server.close + end + end + def test_retrbinary_read_timeout_exceeded commands = [] binary_data = (0..0xff).map {|i| i.chr}.join * 4 * 3 Property changes on: ruby_2_2 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r51046 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/