diff options
author | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-03-12 21:32:03 +0000 |
---|---|---|
committer | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-03-12 21:32:03 +0000 |
commit | 213582c85e18d428c192d620bb930ed0acfcd675 (patch) | |
tree | e3b7a36e05f02ff8b6c3f8fb8112862ab9f46670 /lib | |
parent | c4baab077972e4b3e2e55f7c3828097829ad48bb (diff) |
Merge RubyGems 2.7.6.1 patch [Bug #15637]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@67234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rubygems.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/command_manager.rb | 10 | ||||
-rw-r--r-- | lib/rubygems/commands/owner_command.rb | 5 | ||||
-rw-r--r-- | lib/rubygems/gemcutter_utilities.rb | 7 | ||||
-rw-r--r-- | lib/rubygems/installer.rb | 29 | ||||
-rw-r--r-- | lib/rubygems/package.rb | 10 | ||||
-rw-r--r-- | lib/rubygems/user_interaction.rb | 7 |
7 files changed, 55 insertions, 15 deletions
diff --git a/lib/rubygems.rb b/lib/rubygems.rb index 2762bfcb88..cd7434ca87 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -10,7 +10,7 @@ require 'rbconfig' require 'thread' module Gem - VERSION = "2.7.6" + VERSION = "2.7.6.1" 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 887272378e..3bee1c30a4 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: @@ -140,12 +142,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 @@ -163,7 +165,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 @@ -212,7 +214,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 637b5bdc4d..cac6c5a17d 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 @@ -64,7 +67,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 7c6d6bb364..623d9301b5 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 @@ -145,13 +148,13 @@ module Gem::GemcutterUtilities if block_given? then 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/installer.rb b/lib/rubygems/installer.rb index ee5fedeb64..904d5a0c7c 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -707,9 +707,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\n|\r|\n/ } + raise Gem::InstallError, "#{spec} has an invalid require_paths" + end + + if spec.extensions.any?{|ext| ext =~ /\r\n|\r|\n/ } + 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\n|\r|\n/ || dep.name =~ /\r\n|\r|\n/ } + raise Gem::InstallError, "#{spec} has an invalid dependencies" + end end ## @@ -836,9 +853,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 b924122827..b472b97a07 100644 --- a/lib/rubygems/package.rb +++ b/lib/rubygems/package.rb @@ -425,6 +425,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/user_interaction.rb b/lib/rubygems/user_interaction.rb index cacd782e08..eff8f9533c 100644 --- a/lib/rubygems/user_interaction.rb +++ b/lib/rubygems/user_interaction.rb @@ -6,6 +6,7 @@ #++ require 'rubygems/util' +require 'rubygems/text' ## # Module that defines the default UserInteraction. Any class including this @@ -13,6 +14,8 @@ require 'rubygems/util' module Gem::DefaultUserInteraction + include Gem::Text + ## # The default UI is a class variable of the singleton class for this # module. @@ -160,8 +163,8 @@ module Gem::UserInteraction # Calls +say+ with +msg+ or the results of the block if really_verbose # is true. - def verbose msg = nil - say(msg || yield) if Gem.configuration.really_verbose + def verbose(msg = nil) + say(clean_text(msg || yield)) if Gem.configuration.really_verbose end end |