summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-03-06 09:01:48 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-03-06 09:01:48 +0000
commite0005fdc2734871c4acd7dcf269e1566388794c4 (patch)
tree8ad55fb2e000a2a66be1671e632f170db12c1e2b /lib
parentf5452efcf863e4c15577e53c52e6e8726e70f5c4 (diff)
Backport RubyGems 3.0.3: [Backport #15637]
* Fixed following vulnerabilities: * CVE-2019-8320: Delete directory using symlink when decompressing tar * CVE-2019-8321: Escape sequence injection vulnerability in verbose * CVE-2019-8322: Escape sequence injection vulnerability in gem owner * CVE-2019-8323: Escape sequence injection vulnerability in API response handling * CVE-2019-8324: Installing a malicious gem may lead to arbitrary code execution * CVE-2019-8325: Escape sequence injection vulnerability in errors * see also https://blog.rubygems.org/2019/03/05/3.0.3-released.html git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67182 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/rubygems.rb2
-rw-r--r--lib/rubygems/command_manager.rb10
-rw-r--r--lib/rubygems/commands/owner_command.rb5
-rw-r--r--lib/rubygems/gemcutter_utilities.rb7
-rw-r--r--lib/rubygems/install_update_options.rb2
-rw-r--r--lib/rubygems/installer.rb29
-rw-r--r--lib/rubygems/package.rb10
-rw-r--r--lib/rubygems/requirement.rb17
-rw-r--r--lib/rubygems/test_case.rb1
-rw-r--r--lib/rubygems/user_interaction.rb5
10 files changed, 72 insertions, 16 deletions
diff --git a/lib/rubygems.rb b/lib/rubygems.rb
index 118268dce2..616887838c 100644
--- a/lib/rubygems.rb
+++ b/lib/rubygems.rb
@@ -9,7 +9,7 @@
require 'rbconfig'
module Gem
- VERSION = "3.0.1".freeze
+ VERSION = "3.0.3".freeze
end
# Must be first since it unloads the prelude from 1.9.2
diff --git a/lib/rubygems/command_manager.rb b/lib/rubygems/command_manager.rb
index 8e4e26fdea..8ad723be55 100644
--- a/lib/rubygems/command_manager.rb
+++ b/lib/rubygems/command_manager.rb
@@ -7,6 +7,7 @@
require 'rubygems/command'
require 'rubygems/user_interaction'
+require 'rubygems/text'
##
# The command manager registers and installs all the individual sub-commands
@@ -32,6 +33,7 @@ require 'rubygems/user_interaction'
class Gem::CommandManager
+ include Gem::Text
include Gem::UserInteraction
BUILTIN_COMMANDS = [ # :nodoc:
@@ -145,12 +147,12 @@ class Gem::CommandManager
def run(args, build_args=nil)
process_args(args, build_args)
rescue StandardError, Timeout::Error => ex
- alert_error "While executing gem ... (#{ex.class})\n #{ex}"
+ alert_error clean_text("While executing gem ... (#{ex.class})\n #{ex}")
ui.backtrace ex
terminate_interaction(1)
rescue Interrupt
- alert_error "Interrupted"
+ alert_error clean_text("Interrupted")
terminate_interaction(1)
end
@@ -168,7 +170,7 @@ class Gem::CommandManager
say Gem::VERSION
terminate_interaction 0
when /^-/ then
- alert_error "Invalid option: #{args.first}. See 'gem --help'."
+ alert_error clean_text("Invalid option: #{args.first}. See 'gem --help'.")
terminate_interaction 1
else
cmd_name = args.shift.downcase
@@ -224,7 +226,7 @@ class Gem::CommandManager
rescue Exception => e
e = load_error if load_error
- alert_error "Loading command: #{command_name} (#{e.class})\n\t#{e}"
+ alert_error clean_text("Loading command: #{command_name} (#{e.class})\n\t#{e}")
ui.backtrace e
end
end
diff --git a/lib/rubygems/commands/owner_command.rb b/lib/rubygems/commands/owner_command.rb
index 799f31704a..22b7327683 100644
--- a/lib/rubygems/commands/owner_command.rb
+++ b/lib/rubygems/commands/owner_command.rb
@@ -2,8 +2,11 @@
require 'rubygems/command'
require 'rubygems/local_remote_options'
require 'rubygems/gemcutter_utilities'
+require 'rubygems/text'
class Gem::Commands::OwnerCommand < Gem::Command
+
+ include Gem::Text
include Gem::LocalRemoteOptions
include Gem::GemcutterUtilities
@@ -65,7 +68,7 @@ permission to.
end
with_response response do |resp|
- owners = Gem::SafeYAML.load resp.body
+ owners = Gem::SafeYAML.load clean_text(resp.body)
say "Owners for gem: #{name}"
owners.each do |owner|
diff --git a/lib/rubygems/gemcutter_utilities.rb b/lib/rubygems/gemcutter_utilities.rb
index 3607b61529..e49bff36f9 100644
--- a/lib/rubygems/gemcutter_utilities.rb
+++ b/lib/rubygems/gemcutter_utilities.rb
@@ -1,11 +1,14 @@
# frozen_string_literal: true
require 'rubygems/remote_fetcher'
+require 'rubygems/text'
##
# Utility methods for using the RubyGems API.
module Gem::GemcutterUtilities
+ include Gem::Text
+
# TODO: move to Gem::Command
OptionParser.accept Symbol do |value|
value.to_sym
@@ -162,13 +165,13 @@ module Gem::GemcutterUtilities
if block_given?
yield response
else
- say response.body
+ say clean_text(response.body)
end
else
message = response.body
message = "#{error_prefix}: #{message}" if error_prefix
- say message
+ say clean_text(message)
terminate_interaction 1 # TODO: question this
end
end
diff --git a/lib/rubygems/install_update_options.rb b/lib/rubygems/install_update_options.rb
index f05491a31c..38a0682958 100644
--- a/lib/rubygems/install_update_options.rb
+++ b/lib/rubygems/install_update_options.rb
@@ -30,7 +30,7 @@ module Gem::InstallUpdateOptions
options[:bin_dir] = File.expand_path(value)
end
- add_option(:"Install/Update", '--[no-]document [TYPES]', Array,
+ add_option(:"Install/Update", '--document [TYPES]', Array,
'Generate documentation for installed gems',
'List the documentation types you wish to',
'generate. For example: rdoc,ri') do |value, options|
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
index 6cd073e11d..d26b1e88f6 100644
--- a/lib/rubygems/installer.rb
+++ b/lib/rubygems/installer.rb
@@ -725,9 +725,26 @@ class Gem::Installer
unpack or File.writable?(gem_home)
end
- def verify_spec_name
- return if spec.name =~ Gem::Specification::VALID_NAME_PATTERN
- raise Gem::InstallError, "#{spec} has an invalid name"
+ def verify_spec
+ unless spec.name =~ Gem::Specification::VALID_NAME_PATTERN
+ raise Gem::InstallError, "#{spec} has an invalid name"
+ end
+
+ if spec.raw_require_paths.any?{|path| path =~ /\R/ }
+ raise Gem::InstallError, "#{spec} has an invalid require_paths"
+ end
+
+ if spec.extensions.any?{|ext| ext =~ /\R/ }
+ raise Gem::InstallError, "#{spec} has an invalid extensions"
+ end
+
+ unless spec.specification_version.to_s =~ /\A\d+\z/
+ raise Gem::InstallError, "#{spec} has an invalid specification_version"
+ end
+
+ if spec.dependencies.any? {|dep| dep.type =~ /\R/ || dep.name =~ /\R/ }
+ raise Gem::InstallError, "#{spec} has an invalid dependencies"
+ end
end
##
@@ -876,9 +893,11 @@ TEXT
def pre_install_checks
verify_gem_home options[:unpack]
- ensure_loadable_spec
+ # The name and require_paths must be verified first, since it could contain
+ # ruby code that would be eval'ed in #ensure_loadable_spec
+ verify_spec
- verify_spec_name
+ ensure_loadable_spec
if options[:install_as_default]
Gem.ensure_default_gem_subdirectories gem_home
diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb
index 8695b85fec..3bf4f8fd62 100644
--- a/lib/rubygems/package.rb
+++ b/lib/rubygems/package.rb
@@ -456,6 +456,16 @@ EOM
raise Gem::Package::PathError.new(destination, destination_dir) unless
destination.start_with? destination_dir + '/'
+ begin
+ real_destination = File.expand_path(File.realpath(destination))
+ rescue
+ # it's fine if the destination doesn't exist, because rm -rf'ing it can't cause any damage
+ nil
+ else
+ raise Gem::Package::PathError.new(real_destination, destination_dir) unless
+ real_destination.start_with? destination_dir + '/'
+ end
+
destination.untaint
destination
end
diff --git a/lib/rubygems/requirement.rb b/lib/rubygems/requirement.rb
index 1a73274c01..48f4b00d63 100644
--- a/lib/rubygems/requirement.rb
+++ b/lib/rubygems/requirement.rb
@@ -267,7 +267,22 @@ class Gem::Requirement
def ==(other) # :nodoc:
return unless Gem::Requirement === other
- requirements == other.requirements
+
+ # An == check is always necessary
+ return false unless requirements == other.requirements
+
+ # An == check is sufficient unless any requirements use ~>
+ return true unless _tilde_requirements.any?
+
+ # If any requirements use ~> we use the stricter `#eql?` that also checks
+ # that version precision is the same
+ _tilde_requirements.eql?(other._tilde_requirements)
+ end
+
+ protected
+
+ def _tilde_requirements
+ requirements.select { |r| r.first == "~>" }
end
private
diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb
index 7648ffdc84..a93f749240 100644
--- a/lib/rubygems/test_case.rb
+++ b/lib/rubygems/test_case.rb
@@ -254,6 +254,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni
@orig_gem_env_requirements = ENV.to_hash
ENV['GEM_VENDOR'] = nil
+ ENV['SOURCE_DATE_EPOCH'] = nil
@current_dir = Dir.pwd
@fetcher = nil
diff --git a/lib/rubygems/user_interaction.rb b/lib/rubygems/user_interaction.rb
index 03eac76ea8..0696d54951 100644
--- a/lib/rubygems/user_interaction.rb
+++ b/lib/rubygems/user_interaction.rb
@@ -7,6 +7,7 @@
require 'rubygems/util'
require 'rubygems/deprecate'
+require 'rubygems/text'
##
# Module that defines the default UserInteraction. Any class including this
@@ -14,6 +15,8 @@ require 'rubygems/deprecate'
module Gem::DefaultUserInteraction
+ include Gem::Text
+
##
# The default UI is a class variable of the singleton class for this
# module.
@@ -162,7 +165,7 @@ module Gem::UserInteraction
# is true.
def verbose(msg = nil)
- say(msg || yield) if Gem.configuration.really_verbose
+ say(clean_text(msg || yield)) if Gem.configuration.really_verbose
end
end