Skip to content

Commit f80c5c1

Browse files
committed
Merge tag 'upstream/2.4.3'
Upstream version 2.4.3
2 parents 3839eaa + 18cb328 commit f80c5c1

File tree

15 files changed

+411
-31
lines changed

15 files changed

+411
-31
lines changed

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

parse.y

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,17 @@ static int parser_yyerror(struct parser_params*, const char*);
397397
static int yylex(YYSTYPE*, struct parser_params*);
398398

399399
#ifndef RIPPER
400+
static inline void
401+
set_line_body(NODE *body, int line)
402+
{
403+
if (!body) return;
404+
switch (nd_type(body)) {
405+
case NODE_RESCUE:
406+
case NODE_ENSURE:
407+
nd_set_line(body, line);
408+
}
409+
}
410+
400411
#define yyparse ruby_yyparse
401412

402413
static NODE* node_newnode(struct parser_params *, enum node_type, VALUE, VALUE, VALUE);
@@ -2644,9 +2655,7 @@ primary : literal
26442655
$$ = NEW_NIL();
26452656
}
26462657
else {
2647-
if (nd_type($3) == NODE_RESCUE ||
2648-
nd_type($3) == NODE_ENSURE)
2649-
nd_set_line($3, $<num>2);
2658+
set_line_body($3, $<num>2);
26502659
$$ = NEW_BEGIN($3);
26512660
}
26522661
nd_set_line($$, $<num>2);
@@ -2931,6 +2940,7 @@ primary : literal
29312940
{
29322941
/*%%%*/
29332942
$$ = NEW_CLASS($2, $5, $3);
2943+
set_line_body($5, $<num>4);
29342944
nd_set_line($$, $<num>4);
29352945
/*%
29362946
$$ = dispatch3(class, $2, $3, $5);
@@ -2950,6 +2960,7 @@ primary : literal
29502960
{
29512961
/*%%%*/
29522962
$$ = NEW_SCLASS($3, $6);
2963+
set_line_body($6, nd_line($3));
29532964
fixpos($$, $3);
29542965
/*%
29552966
$$ = dispatch2(sclass, $3, $6);
@@ -2973,6 +2984,7 @@ primary : literal
29732984
{
29742985
/*%%%*/
29752986
$$ = NEW_MODULE($2, $4);
2987+
set_line_body($4, $<num>3);
29762988
nd_set_line($$, $<num>3);
29772989
/*%
29782990
$$ = dispatch2(module, $2, $4);
@@ -2997,6 +3009,7 @@ primary : literal
29973009
NODE *body = remove_begin($6);
29983010
reduce_nodes(&body);
29993011
$$ = NEW_DEFN($2, $5, body, METHOD_VISI_PRIVATE);
3012+
set_line_body(body, $<num>1);
30003013
nd_set_line($$, $<num>1);
30013014
/*%
30023015
$$ = dispatch3(def, $2, $5, $6);
@@ -3022,6 +3035,7 @@ primary : literal
30223035
NODE *body = remove_begin($8);
30233036
reduce_nodes(&body);
30243037
$$ = NEW_DEFS($2, $5, $7, body);
3038+
set_line_body(body, $<num>1);
30253039
nd_set_line($$, $<num>1);
30263040
/*%
30273041
$$ = dispatch5(defs, $2, $3, $5, $7, $8);

0 commit comments

Comments
 (0)