Skip to content

Commit 18cb328

Browse files
committed
Imported Upstream version 2.4.3
1 parent 5749eb3 commit 18cb328

File tree

16 files changed

+415
-33
lines changed

16 files changed

+415
-33
lines changed

configure.in

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,13 +1403,15 @@ AC_ARG_WITH([gmp],
14031403
AS_IF([test "x$with_gmp" != xno],
14041404
[AC_CHECK_HEADERS(gmp.h)
14051405
AS_IF([test "x$ac_cv_header_gmp_h" != xno],
1406-
AC_SEARCH_LIBS([__gmpz_init], [gmp]))])
1406+
AC_SEARCH_LIBS([__gmpz_init], [gmp],
1407+
[AC_DEFINE(HAVE_LIBGMP, 1)]))])
14071408

14081409
AC_ARG_WITH([jemalloc],
14091410
[AS_HELP_STRING([--with-jemalloc],[use jemalloc allocator])],
14101411
[with_jemalloc=$withval], [with_jemalloc=no])
14111412
AS_IF([test "x$with_jemalloc" = xyes],[
1412-
AC_SEARCH_LIBS([malloc_conf], [jemalloc], [], [with_jemalloc=no])
1413+
AC_SEARCH_LIBS([malloc_conf], [jemalloc],
1414+
[AC_DEFINE(HAVE_LIBJEMALLOC, 1)], [with_jemalloc=no])
14131415
AC_CHECK_HEADER(jemalloc/jemalloc.h, [
14141416
AC_DEFINE(RUBY_ALTERNATIVE_MALLOC_HEADER, [<jemalloc/jemalloc.h>])
14151417
])

lib/net/ftp.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -754,10 +754,10 @@ def getbinaryfile(remotefile, localfile = File.basename(remotefile),
754754
if localfile
755755
if @resume
756756
rest_offset = File.size?(localfile)
757-
f = open(localfile, "a")
757+
f = File.open(localfile, "a")
758758
else
759759
rest_offset = nil
760-
f = open(localfile, "w")
760+
f = File.open(localfile, "w")
761761
end
762762
elsif !block_given?
763763
result = String.new
@@ -787,7 +787,7 @@ def gettextfile(remotefile, localfile = File.basename(remotefile),
787787
f = nil
788788
result = nil
789789
if localfile
790-
f = open(localfile, "w")
790+
f = File.open(localfile, "w")
791791
elsif !block_given?
792792
result = String.new
793793
end
@@ -833,7 +833,7 @@ def putbinaryfile(localfile, remotefile = File.basename(localfile),
833833
else
834834
rest_offset = nil
835835
end
836-
f = open(localfile)
836+
f = File.open(localfile)
837837
begin
838838
f.binmode
839839
if rest_offset
@@ -852,7 +852,7 @@ def putbinaryfile(localfile, remotefile = File.basename(localfile),
852852
# passing in the transmitted data one line at a time.
853853
#
854854
def puttextfile(localfile, remotefile = File.basename(localfile), &block) # :yield: line
855-
f = open(localfile)
855+
f = File.open(localfile)
856856
begin
857857
storlines("STOR #{remotefile}", f, &block)
858858
ensure

lib/rubygems.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
require 'thread'
1111

1212
module Gem
13-
VERSION = "2.6.13"
13+
VERSION = "2.6.14"
1414
end
1515

1616
# Must be first since it unloads the prelude from 1.9.2
@@ -675,7 +675,7 @@ def self.load_yaml
675675

676676
unless test_syck
677677
begin
678-
gem 'psych', '>= 1.2.1'
678+
gem 'psych', '>= 2.0.0'
679679
rescue Gem::LoadError
680680
# It's OK if the user does not have the psych gem installed. We will
681681
# attempt to require the stdlib version
@@ -699,6 +699,7 @@ def self.load_yaml
699699
end
700700

701701
require 'yaml'
702+
require 'rubygems/safe_yaml'
702703

703704
# If we're supposed to be using syck, then we may have to force
704705
# activate it via the YAML::ENGINE API.

lib/rubygems/config_file.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ def load_file(filename)
345345
return {} unless filename and File.exist? filename
346346

347347
begin
348-
content = YAML.load(File.read(filename))
348+
content = Gem::SafeYAML.load(File.read(filename))
349349
unless content.kind_of? Hash
350350
warn "Failed to load #{filename} because it doesn't contain valid YAML hash"
351351
return {}

lib/rubygems/package.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def read_checksums gem
468468

469469
@checksums = gem.seek 'checksums.yaml.gz' do |entry|
470470
Zlib::GzipReader.wrap entry do |gz_io|
471-
YAML.load gz_io.read
471+
Gem::SafeYAML.safe_load gz_io.read
472472
end
473473
end
474474
end

lib/rubygems/package/old.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def file_list io # :nodoc:
101101
header << line
102102
end
103103

104-
YAML.load header
104+
Gem::SafeYAML.safe_load header
105105
end
106106

107107
##

lib/rubygems/safe_yaml.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
module Gem
2+
3+
###
4+
# This module is used for safely loading YAML specs from a gem. The
5+
# `safe_load` method defined on this module is specifically designed for
6+
# loading Gem specifications. For loading other YAML safely, please see
7+
# Psych.safe_load
8+
9+
module SafeYAML
10+
WHITELISTED_CLASSES = %w(
11+
Symbol
12+
Time
13+
Date
14+
Gem::Dependency
15+
Gem::Platform
16+
Gem::Requirement
17+
Gem::Specification
18+
Gem::Version
19+
Gem::Version::Requirement
20+
YAML::Syck::DefaultKey
21+
Syck::DefaultKey
22+
)
23+
24+
WHITELISTED_SYMBOLS = %w(
25+
development
26+
runtime
27+
)
28+
29+
if ::YAML.respond_to? :safe_load
30+
def self.safe_load input
31+
::YAML.safe_load(input, WHITELISTED_CLASSES, WHITELISTED_SYMBOLS, true)
32+
end
33+
34+
def self.load input
35+
::YAML.safe_load(input, [::Symbol])
36+
end
37+
else
38+
warn "YAML safe loading is not available. Please upgrade psych to a version that supports safe loading (>= 2.0)."
39+
def self.safe_load input, *args
40+
::YAML.load input
41+
end
42+
43+
def self.load input
44+
::YAML.load input
45+
end
46+
end
47+
end
48+
end

lib/rubygems/specification.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ def self.from_yaml(input)
11011101
Gem.load_yaml
11021102

11031103
input = normalize_yaml_input input
1104-
spec = YAML.load input
1104+
spec = Gem::SafeYAML.safe_load input
11051105

11061106
if spec && spec.class == FalseClass then
11071107
raise Gem::EndOfYAMLException

lib/webrick/httpserver.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,12 @@ def compile
267267
k.sort!
268268
k.reverse!
269269
k.collect!{|path| Regexp.escape(path) }
270-
@scanner = Regexp.new("^(" + k.join("|") +")(?=/|$)")
270+
@scanner = Regexp.new("\\A(" + k.join("|") +")(?=/|\\z)")
271271
end
272272

273273
def normalize(dir)
274274
ret = dir ? dir.dup : ""
275-
ret.sub!(%r|/+$|, "")
275+
ret.sub!(%r|/+\z|, "")
276276
ret
277277
end
278278
end

lib/webrick/server.rb

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -252,18 +252,26 @@ def run(sock)
252252
# the client socket.
253253

254254
def accept_client(svr)
255-
sock = nil
256-
begin
257-
sock = svr.accept
258-
sock.sync = true
259-
Utils::set_non_blocking(sock)
260-
rescue Errno::ECONNRESET, Errno::ECONNABORTED,
261-
Errno::EPROTO, Errno::EINVAL
262-
rescue StandardError => ex
263-
msg = "#{ex.class}: #{ex.message}\n\t#{ex.backtrace[0]}"
264-
@logger.error msg
255+
case sock = svr.to_io.accept_nonblock(exception: false)
256+
when :wait_readable
257+
nil
258+
else
259+
if svr.respond_to?(:start_immediately)
260+
sock = OpenSSL::SSL::SSLSocket.new(sock, ssl_context)
261+
sock.sync_close = true
262+
# we cannot do OpenSSL::SSL::SSLSocket#accept here because
263+
# a slow client can prevent us from accepting connections
264+
# from other clients
265+
end
266+
sock
265267
end
266-
return sock
268+
rescue Errno::ECONNRESET, Errno::ECONNABORTED,
269+
Errno::EPROTO, Errno::EINVAL
270+
nil
271+
rescue StandardError => ex
272+
msg = "#{ex.class}: #{ex.message}\n\t#{ex.backtrace[0]}"
273+
@logger.error msg
274+
nil
267275
end
268276

269277
##
@@ -286,6 +294,16 @@ def start_thread(sock, &block)
286294
@logger.debug "accept: <address unknown>"
287295
raise
288296
end
297+
if sock.respond_to?(:sync_close=) && @config[:SSLStartImmediately]
298+
WEBrick::Utils.timeout(@config[:RequestTimeout]) do
299+
begin
300+
sock.accept # OpenSSL::SSL::SSLSocket#accept
301+
rescue Errno::ECONNRESET, Errno::ECONNABORTED,
302+
Errno::EPROTO, Errno::EINVAL
303+
Thread.exit
304+
end
305+
end
306+
end
289307
call_callback(:AcceptCallback, sock)
290308
block ? block.call(sock) : run(sock)
291309
rescue Errno::ENOTCONN

0 commit comments

Comments
 (0)