[rubygems/f14] Backport patch for rubygems/pull/165, code-injection in Gem::Specification#ruby_code issue

Mamoru Tasaka mtasaka at fedoraproject.org
Sat Aug 27 22:36:56 UTC 2011


commit 7b9e97983e0287b684f55f4fbc4dd370e0af24cd
Author: Mamoru Tasaka <tasaka1 at localhost.localdomain>
Date:   Sun Aug 28 07:36:32 2011 +0900

    Backport patch for rubygems/pull/165, code-injection in
    Gem::Specification#ruby_code issue

 rubygems-1.3.7-escape-string-skip-test.patch |   32 +++++
 rubygems-1.3.7-escape-string.patch           |  160 ++++++++++++++++++++++++++
 rubygems-1.3.7-test-fix.patch                |   10 ++
 rubygems.spec                                |   41 +++++++-
 4 files changed, 242 insertions(+), 1 deletions(-)
---
diff --git a/rubygems-1.3.7-escape-string-skip-test.patch b/rubygems-1.3.7-escape-string-skip-test.patch
new file mode 100644
index 0000000..d77e9eb
--- /dev/null
+++ b/rubygems-1.3.7-escape-string-skip-test.patch
@@ -0,0 +1,32 @@
+--- rubygems-1.3.7/test/test_gem_specification.rb.specf	2011-08-28 06:36:45.000000000 +0900
++++ rubygems-1.3.7/test/test_gem_specification.rb	2011-08-28 06:47:38.000000000 +0900
+@@ -130,6 +130,9 @@
+   end
+ 
+   def test_self_load_escape_curly
++    puts "spec_file not supported yet"
++    return
++
+     @a2.name = 'a};raise "improper escaping";%q{'
+ 
+     full_path = @a2.spec_file
+@@ -145,6 +148,9 @@
+   end
+ 
+   def test_self_load_escape_interpolation
++    puts "spec_file not supported yet"
++    return
++
+     @a2.name = 'a#{raise %<improper escaping>}'
+ 
+     full_path = @a2.spec_file
+@@ -160,6 +166,9 @@
+   end
+ 
+   def test_self_load_escape_quote
++    puts "spec_file not supported yet"
++    return
++
+     @a2.name = 'a";raise "improper escaping";"'
+ 
+     full_path = @a2.spec_file
diff --git a/rubygems-1.3.7-escape-string.patch b/rubygems-1.3.7-escape-string.patch
new file mode 100644
index 0000000..2b75e02
--- /dev/null
+++ b/rubygems-1.3.7-escape-string.patch
@@ -0,0 +1,160 @@
+--- rubygems-1.3.7/lib/rubygems/specification.rb.escape	2010-04-22 13:43:03.000000000 +0900
++++ rubygems-1.3.7/lib/rubygems/specification.rb	2011-08-28 06:25:31.000000000 +0900
+@@ -1038,11 +1038,11 @@
+ 
+   def ruby_code(obj)
+     case obj
+-    when String            then '%q{' + obj + '}'
++    when String            then obj.dump
+     when Array             then obj.inspect
+-    when Gem::Version      then obj.to_s.inspect
+-    when Date              then '%q{' + obj.strftime('%Y-%m-%d') + '}'
+-    when Time              then '%q{' + obj.strftime('%Y-%m-%d') + '}'
++    when Gem::Version      then obj.to_s.dump
++    when Date              then obj.strftime('%Y-%m-%d').dump
++    when Time              then obj.strftime('%Y-%m-%d').dump
+     when Numeric           then obj.inspect
+     when true, false, nil  then obj.inspect
+     when Gem::Platform     then "Gem::Platform.new(#{obj.to_a.inspect})"
+--- rubygems-1.3.7/test/test_gem_specification.rb.escape	2010-04-22 13:43:01.000000000 +0900
++++ rubygems-1.3.7/test/test_gem_specification.rb	2011-08-28 06:36:45.000000000 +0900
+@@ -129,6 +129,51 @@
+     assert_equal @a2, gs
+   end
+ 
++  def test_self_load_escape_curly
++    @a2.name = 'a};raise "improper escaping";%q{'
++
++    full_path = @a2.spec_file
++    write_file full_path do |io|
++      io.write @a2.to_ruby_for_cache
++    end
++
++    spec = Gem::Specification.load full_path
++
++    @a2.files.clear
++
++    assert_equal @a2, spec
++  end
++
++  def test_self_load_escape_interpolation
++    @a2.name = 'a#{raise %<improper escaping>}'
++
++    full_path = @a2.spec_file
++    write_file full_path do |io|
++      io.write @a2.to_ruby_for_cache
++    end
++
++    spec = Gem::Specification.load full_path
++
++    @a2.files.clear
++
++    assert_equal @a2, spec
++  end
++
++  def test_self_load_escape_quote
++    @a2.name = 'a";raise "improper escaping";"'
++
++    full_path = @a2.spec_file
++    write_file full_path do |io|
++      io.write @a2.to_ruby_for_cache
++    end
++
++    spec = Gem::Specification.load full_path
++
++    @a2.files.clear
++
++    assert_equal @a2, spec
++  end
++
+   def test_self_load_legacy_ruby
+     spec = eval LEGACY_RUBY_SPEC
+     assert_equal 'keyedlist', spec.name
+@@ -762,19 +807,19 @@
+ # -*- encoding: utf-8 -*-
+ 
+ Gem::Specification.new do |s|
+-  s.name = %q{a}
+-  s.version = \"2\"
++  s.name = "a"
++  s.version = "2"
+ 
+   s.required_rubygems_version = Gem::Requirement.new(\"> 0\") if s.respond_to? :required_rubygems_version=
+-  s.authors = [\"A User\"]
+-  s.date = %q{#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}}
+-  s.description = %q{This is a test description}
+-  s.email = %q{example at example.com}
+-  s.files = [\"lib/code.rb\"]
+-  s.homepage = %q{http://example.com}
+-  s.require_paths = [\"lib\"]
+-  s.rubygems_version = %q{#{Gem::VERSION}}
+-  s.summary = %q{this is a summary}
++  s.authors = ["A User"]
++  s.date = "#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}"
++  s.description = "This is a test description"
++  s.email = "example at example.com"
++  s.files = ["lib/code.rb"]
++  s.homepage = "http://example.com"
++  s.require_paths = ["lib"]
++  s.rubygems_version = "#{Gem::VERSION}"
++  s.summary = "this is a summary"
+ 
+   if s.respond_to? :specification_version then
+     current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+@@ -809,27 +854,27 @@
+ # -*- encoding: utf-8 -*-
+ 
+ Gem::Specification.new do |s|
+-  s.name = %q{a}
+-  s.version = \"1\"
++  s.name = "a"
++  s.version = "1"
+   s.platform = Gem::Platform.new(#{expected_platform})
+ 
+   s.required_rubygems_version = Gem::Requirement.new(\">= 0\") if s.respond_to? :required_rubygems_version=
+-  s.authors = [\"A User\"]
+-  s.date = %q{#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}}
+-  s.default_executable = %q{exec}
+-  s.description = %q{This is a test description}
+-  s.email = %q{example at example.com}
+-  s.executables = [\"exec\"]
+-  s.extensions = [\"ext/a/extconf.rb\"]
+-  s.files = [\"lib/code.rb\", \"test/suite.rb\", \"bin/exec\", \"ext/a/extconf.rb\"]
+-  s.homepage = %q{http://example.com}
+-  s.licenses = [\"MIT\"]
+-  s.require_paths = [\"lib\"]
+-  s.requirements = [\"A working computer\"]
+-  s.rubyforge_project = %q{example}
+-  s.rubygems_version = %q{#{Gem::VERSION}}
+-  s.summary = %q{this is a summary}
+-  s.test_files = [\"test/suite.rb\"]
++  s.authors = ["A User"]
++  s.date = "#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}"
++  s.default_executable = "exec"
++  s.description = "This is a test description"
++  s.email = "example at example.com"
++  s.executables = ["exec"]
++  s.extensions = ["ext/a/extconf.rb"]
++  s.files = ["lib/code.rb", "test/suite.rb", "bin/exec", "ext/a/extconf.rb"]
++  s.homepage = "http://example.com"
++  s.licenses = ["MIT"]
++  s.require_paths = ["lib"]
++  s.requirements = ["A working computer"]
++  s.rubyforge_project = "example"
++  s.rubygems_version = "#{Gem::VERSION}"
++  s.summary = "this is a summary"
++  s.test_files = ["test/suite.rb"]
+ 
+   if s.respond_to? :specification_version then
+     current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+--- rubygems-1.3.7/test/test_gem_commands_specification_command.rb.escape	2010-02-07 19:58:54.000000000 +0900
++++ rubygems-1.3.7/test/test_gem_commands_specification_command.rb	2011-08-28 06:31:23.000000000 +0900
+@@ -131,7 +131,7 @@
+     end
+ 
+     assert_match %r|Gem::Specification.new|, @ui.output
+-    assert_match %r|s.name = %q\{foo\}|, @ui.output
++    assert_match %r|s.name = "foo"|, @ui.output
+     assert_equal '', @ui.error
+   end
+ 
diff --git a/rubygems-1.3.7-test-fix.patch b/rubygems-1.3.7-test-fix.patch
new file mode 100644
index 0000000..291148f
--- /dev/null
+++ b/rubygems-1.3.7-test-fix.patch
@@ -0,0 +1,10 @@
+--- rubygems-1.3.7/test/test_gem_gemcutter_utilities.rb.debug	2010-02-21 09:50:03.000000000 +0900
++++ rubygems-1.3.7/test/test_gem_gemcutter_utilities.rb	2011-08-28 07:29:31.000000000 +0900
+@@ -1,6 +1,7 @@
+ require File.expand_path('../gemutilities', __FILE__)
+ require 'rubygems'
+ require 'rubygems/gemcutter_utilities'
++require 'rubygems/command'
+ 
+ class TestGemGemcutterUtilities < RubyGemTestCase
+ 
diff --git a/rubygems.spec b/rubygems.spec
index 75eed39..e4a28a7 100644
--- a/rubygems.spec
+++ b/rubygems.spec
@@ -8,7 +8,7 @@
 Summary: The Ruby standard for packaging ruby libraries
 Name: rubygems
 Version: 1.3.7
-Release: 2%{?dist}
+Release: 3%{?dist}
 Group: Development/Libraries
 # No GPL version is specified.
 License: Ruby or GPL+
@@ -17,6 +17,15 @@ Source0: http://rubyforge.org/frs/download.php/%{repoid}/rubygems-%{version}.tgz
 Patch0: rubygems-1.3.7-noarch-gemdir.patch
 # Will discuss upstream
 Patch1: rubygems-1.3.7-show-extension-build-process-in-sync.patch
+# https://github.com/rubygems/rubygems/pull/165
+# https://github.com/rubygems/rubygems/commit/bfee6f154a3fef71eacce9667fe0bc061f60169c
+# Modified for 1.7.2
+Patch2:         rubygems-1.3.7-escape-string.patch
+# ... and spec_file is not supported yet
+Patch3:         rubygems-1.3.7-escape-string-skip-test.patch
+# Make tests succeed
+Patch4:		rubygems-1.3.7-test-fix.patch
+
 BuildRoot: %{_tmppath}/%{name}-%{version}-root-%(%{__id_u} -n)
 Requires: ruby(abi) = 1.8 ruby-rdoc
 BuildRequires:  ruby ruby-rdoc
@@ -31,6 +40,9 @@ libraries.
 %setup -q
 %patch0 -p1 -b .noarch
 %patch1 -p1 -b .insync
+%patch2 -p1 -b .esc
+%patch3 -p1 -b .esc.skip
+%patch4 -p1 -b .test
 
 # Some of the library files start with #! which rpmlint doesn't like
 # and doesn't make much sense
@@ -60,6 +72,29 @@ mkdir -p $RPM_BUILD_ROOT%{gem_home}/{cache,gems,specifications,doc}
 %clean
 rm -rf $RPM_BUILD_ROOT
 
+%check
+rm -f SKIPLIST
+cat > SKIPLIST <<EOF
+test/test_gem_command_manager.rb
+test/test_gem_ext_configure_builder.rb
+test/test_gem_ext_ext_conf_builder.rb
+EOF
+
+cat SKIPLIST | while read file
+do
+	mv $file $file.skip
+done
+
+ls -1 test/test_*.rb | sort | while read f
+do
+	ruby -Ilib $f
+done
+
+cat SKIPLIST | while read file
+do
+	mv $file.skip $file
+done
+
 %files
 %defattr(-, root, root, -)
 %doc README ChangeLog
@@ -75,6 +110,10 @@ rm -rf $RPM_BUILD_ROOT
 %{ruby_sitelib}/*
 
 %changelog
+* Sun Aug 28 2011 Mamoru Tasaka <mtasaka at fedoraproject.org> - 1.3.7-3
+- Backport patch for rubygems/pull/165, code-injection in 
+  Gem::Specification#ruby_code issue
+
 * Fri Oct  8 2010 Mamoru Tasaka <mtasaka at ioa.s.u-tokyo.ac.jp> - 1.3.7-2
 - Show build process of extension library in sync
 


More information about the scm-commits mailing list