Skip to content

Commit

Permalink
Showing 7 changed files with 75 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/ruby/stdlib/rubygems.rb
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
require 'thread'

module Gem
VERSION = "2.6.14"
VERSION = "2.6.14.1"
end

# Must be first since it unloads the prelude from 1.9.2
2 changes: 1 addition & 1 deletion lib/ruby/stdlib/rubygems/commands/owner_command.rb
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ def show_owners name
end

with_response response do |resp|
owners = YAML.load resp.body
owners = Gem::SafeYAML.load resp.body

say "Owners for gem: #{name}"
owners.each do |owner|
37 changes: 33 additions & 4 deletions lib/ruby/stdlib/rubygems/package.rb
Original file line number Diff line number Diff line change
@@ -378,7 +378,7 @@ def extract_tar_gz io, destination_dir, pattern = "*" # :nodoc:
File.dirname destination
end

FileUtils.mkdir_p mkdir, mkdir_options
mkdir_p_safe mkdir, mkdir_options, destination_dir, entry.full_name

open destination, 'wb' do |out|
out.write entry.read
@@ -416,20 +416,35 @@ def install_location filename, destination_dir # :nodoc:
raise Gem::Package::PathError.new(filename, destination_dir) if
filename.start_with? '/'

destination_dir = File.realpath destination_dir if
File.respond_to? :realpath
destination_dir = realpath destination_dir
destination_dir = File.expand_path destination_dir

destination = File.join destination_dir, filename
destination = File.expand_path destination

raise Gem::Package::PathError.new(destination, destination_dir) unless
destination.start_with? destination_dir
destination.start_with? destination_dir + '/'

destination.untaint
destination
end

def mkdir_p_safe mkdir, mkdir_options, destination_dir, file_name
destination_dir = realpath File.expand_path(destination_dir)
parts = mkdir.split(File::SEPARATOR)
parts.reduce do |path, basename|
path = realpath path unless path == ""
path = File.expand_path(path + File::SEPARATOR + basename)
lstat = File.lstat path rescue nil
if !lstat || !lstat.directory?
unless path.start_with? destination_dir and (FileUtils.mkdir path, mkdir_options rescue false)
raise Gem::Package::PathError.new(file_name, destination_dir)
end
end
path
end
end

##
# Loads a Gem::Specification from the TarEntry +entry+

@@ -603,6 +618,10 @@ def verify_files gem
raise Gem::Package::FormatError.new \
'package content (data.tar.gz) is missing', @gem
end

if duplicates = @files.group_by {|f| f }.select {|k,v| v.size > 1 }.map(&:first) and duplicates.any?
raise Gem::Security::Exception, "duplicate files in the package: (#{duplicates.map(&:inspect).join(', ')})"
end
end

##
@@ -616,6 +635,16 @@ def verify_gz entry # :nodoc:
raise Gem::Package::FormatError.new(e.message, entry.full_name)
end

if File.respond_to? :realpath
def realpath file
File.realpath file
end
else
def realpath file
file
end
end

end

require 'rubygems/package/digest_io'
23 changes: 14 additions & 9 deletions lib/ruby/stdlib/rubygems/package/tar_header.rb
Original file line number Diff line number Diff line change
@@ -104,25 +104,30 @@ def self.from(stream)
fields = header.unpack UNPACK_FORMAT

new :name => fields.shift,
:mode => fields.shift.oct,
:uid => fields.shift.oct,
:gid => fields.shift.oct,
:size => fields.shift.oct,
:mtime => fields.shift.oct,
:checksum => fields.shift.oct,
:mode => strict_oct(fields.shift),
:uid => strict_oct(fields.shift),
:gid => strict_oct(fields.shift),
:size => strict_oct(fields.shift),
:mtime => strict_oct(fields.shift),
:checksum => strict_oct(fields.shift),
:typeflag => fields.shift,
:linkname => fields.shift,
:magic => fields.shift,
:version => fields.shift.oct,
:version => strict_oct(fields.shift),
:uname => fields.shift,
:gname => fields.shift,
:devmajor => fields.shift.oct,
:devminor => fields.shift.oct,
:devmajor => strict_oct(fields.shift),
:devminor => strict_oct(fields.shift),
:prefix => fields.shift,

:empty => empty
end

def self.strict_oct(str)
return str.oct if str =~ /\A[0-7]*\z/
raise ArgumentError, "#{str.inspect} is not an octal string"
end

##
# Creates a new TarHeader using +vals+

2 changes: 2 additions & 0 deletions lib/ruby/stdlib/rubygems/package/tar_writer.rb
Original file line number Diff line number Diff line change
@@ -196,6 +196,8 @@ def add_file_signed name, mode, signer
digest_name == signer.digest_name
end

raise "no #{signer.digest_name} in #{digests.values.compact}" unless signature_digest

if signer.key then
signature = signer.sign signature_digest.digest

14 changes: 13 additions & 1 deletion lib/ruby/stdlib/rubygems/server.rb
Original file line number Diff line number Diff line change
@@ -631,6 +631,18 @@ def root(req, res)
executables = nil if executables.empty?
executables.last["is_last"] = true if executables

# Pre-process spec homepage for safety reasons
begin
homepage_uri = URI.parse(spec.homepage)
if [URI::HTTP, URI::HTTPS].member? homepage_uri.class
homepage_uri = spec.homepage
else
homepage_uri = "."
end
rescue URI::InvalidURIError
homepage_uri = "."
end

specs << {
"authors" => spec.authors.sort.join(", "),
"date" => spec.date.to_s,
@@ -640,7 +652,7 @@ def root(req, res)
"only_one_executable" => (executables && executables.size == 1),
"full_name" => spec.full_name,
"has_deps" => !deps.empty?,
"homepage" => spec.homepage,
"homepage" => homepage_uri,
"name" => spec.name,
"rdoc_installed" => Gem::RDoc.new(spec).rdoc_installed?,
"ri_installed" => Gem::RDoc.new(spec).ri_installed?,
15 changes: 11 additions & 4 deletions lib/ruby/stdlib/rubygems/specification.rb
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
require 'rubygems/stub_specification'
require 'rubygems/util/list'
require 'stringio'
require 'uri'

##
# The Specification class contains the information for a Gem. Typically
@@ -2810,10 +2811,16 @@ def validate packaging = true
raise Gem::InvalidSpecificationException, "#{lazy} is not a summary"
end

if homepage and not homepage.empty? and
homepage !~ /\A[a-z][a-z\d+.-]*:/i then
raise Gem::InvalidSpecificationException,
"\"#{homepage}\" is not a URI"
# Make sure a homepage is valid HTTP/HTTPS URI
if homepage and not homepage.empty?
begin
homepage_uri = URI.parse(homepage)
unless [URI::HTTP, URI::HTTPS].member? homepage_uri.class
raise Gem::InvalidSpecificationException, "\"#{homepage}\" is not a valid HTTP URI"
end
rescue URI::InvalidURIError
raise Gem::InvalidSpecificationException, "\"#{homepage}\" is not a valid HTTP URI"
end
end

# Warnings

0 comments on commit 0b06b48

Please sign in to comment.