mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
merge revision(s) 19320,19322:
* lib/rexml/document.rb: limit entity expansion. Thanks, Luka Treiber, Mitja Kolsek, and Michael Koziarski. backported from trunk r19033, r19317, r19318. * lib/rexml/entity.rb: ditto. * test/rexml/test_document.rb: ditto. * NEWS: added an entry for REXML. * lib/rexml/document.rb: fixed typo. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@21744 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8837f59485
commit
d3bec17ee7
6 changed files with 117 additions and 4 deletions
16
ChangeLog
16
ChangeLog
|
|
@ -1,3 +1,19 @@
|
||||||
|
Fri Jan 23 11:49:45 2009 Shugo Maeda <shugo@ruby-lang.org>
|
||||||
|
|
||||||
|
* NEWS: added an entry for REXML.
|
||||||
|
|
||||||
|
* lib/rexml/document.rb: fixed typo.
|
||||||
|
|
||||||
|
Fri Jan 23 11:49:45 2009 Shugo Maeda <shugo@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/rexml/document.rb: limit entity expansion. Thanks, Luka
|
||||||
|
Treiber, Mitja Kolsek, and Michael Koziarski. backported from
|
||||||
|
trunk r19033, r19317, r19318.
|
||||||
|
|
||||||
|
* lib/rexml/entity.rb: ditto.
|
||||||
|
|
||||||
|
* test/rexml/test_document.rb: ditto.
|
||||||
|
|
||||||
Thu Jan 22 15:19:39 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Thu Jan 22 15:19:39 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* marshal.c (marshal_load): arg.data is no longer a VALUE but a
|
* marshal.c (marshal_load): arg.data is no longer a VALUE but a
|
||||||
|
|
|
||||||
9
NEWS
9
NEWS
|
|
@ -7,6 +7,15 @@ Note that each entry is kept so brief that no reason behind or
|
||||||
reference information is supplied with. For a full list of changes
|
reference information is supplied with. For a full list of changes
|
||||||
with all sufficient information, see the ChangeLog file.
|
with all sufficient information, see the ChangeLog file.
|
||||||
|
|
||||||
|
* REXML
|
||||||
|
|
||||||
|
* REXML::Document.entity_expansion_limit=
|
||||||
|
|
||||||
|
New method to set the entity expansion limit. By default the limit is
|
||||||
|
set to 10000. See the following URL for details.
|
||||||
|
|
||||||
|
http://www.ruby-lang.org/en/news/2008/08/23/dos-vulnerability-in-rexml/
|
||||||
|
|
||||||
== Changes since the 1.8.6 release
|
== Changes since the 1.8.6 release
|
||||||
|
|
||||||
=== Configuration changes
|
=== Configuration changes
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ module REXML
|
||||||
# @param context if supplied, contains the context of the document;
|
# @param context if supplied, contains the context of the document;
|
||||||
# this should be a Hash.
|
# this should be a Hash.
|
||||||
def initialize( source = nil, context = {} )
|
def initialize( source = nil, context = {} )
|
||||||
|
@entity_expansion_count = 0
|
||||||
super()
|
super()
|
||||||
@context = context
|
@context = context
|
||||||
return if source.nil?
|
return if source.nil?
|
||||||
|
|
@ -200,6 +201,27 @@ module REXML
|
||||||
Parsers::StreamParser.new( source, listener ).parse
|
Parsers::StreamParser.new( source, listener ).parse
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@entity_expansion_limit = 10_000
|
||||||
|
|
||||||
|
# Set the entity expansion limit. By default the limit is set to 10000.
|
||||||
|
def Document::entity_expansion_limit=( val )
|
||||||
|
@@entity_expansion_limit = val
|
||||||
|
end
|
||||||
|
|
||||||
|
# Get the entity expansion limit. By default the limit is set to 10000.
|
||||||
|
def Document::entity_expansion_limit
|
||||||
|
return @@entity_expansion_limit
|
||||||
|
end
|
||||||
|
|
||||||
|
attr_reader :entity_expansion_count
|
||||||
|
|
||||||
|
def record_entity_expansion
|
||||||
|
@entity_expansion_count += 1
|
||||||
|
if @entity_expansion_count > @@entity_expansion_limit
|
||||||
|
raise "number of entity expansions exceeded, processing aborted."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def build( source )
|
def build( source )
|
||||||
Parsers::TreeParser.new( source, self ).parse
|
Parsers::TreeParser.new( source, self ).parse
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,7 @@ module REXML
|
||||||
# all entities -- both %ent; and &ent; entities. This differs from
|
# all entities -- both %ent; and &ent; entities. This differs from
|
||||||
# +value()+ in that +value+ only replaces %ent; entities.
|
# +value()+ in that +value+ only replaces %ent; entities.
|
||||||
def unnormalized
|
def unnormalized
|
||||||
|
document.record_entity_expansion
|
||||||
v = value()
|
v = value()
|
||||||
return nil if v.nil?
|
return nil if v.nil?
|
||||||
@unnormalized = Text::unnormalize(v, parent)
|
@unnormalized = Text::unnormalize(v, parent)
|
||||||
|
|
|
||||||
65
test/rexml/test_document.rb
Normal file
65
test/rexml/test_document.rb
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
require "rexml/document"
|
||||||
|
require "test/unit"
|
||||||
|
|
||||||
|
class REXML::TestDocument < Test::Unit::TestCase
|
||||||
|
def test_new
|
||||||
|
doc = REXML::Document.new(<<EOF)
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<message>Hello world!</message>
|
||||||
|
EOF
|
||||||
|
assert_equal("Hello world!", doc.root.children.first.value)
|
||||||
|
end
|
||||||
|
|
||||||
|
XML_WITH_NESTED_ENTITY = <<EOF
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE member [
|
||||||
|
<!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;">
|
||||||
|
<!ENTITY b "&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;">
|
||||||
|
<!ENTITY c "&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;">
|
||||||
|
<!ENTITY d "&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;">
|
||||||
|
<!ENTITY e "&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;">
|
||||||
|
<!ENTITY f "&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;">
|
||||||
|
<!ENTITY g "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx">
|
||||||
|
]>
|
||||||
|
<member>
|
||||||
|
&a;
|
||||||
|
</member>
|
||||||
|
EOF
|
||||||
|
|
||||||
|
XML_WITH_4_ENTITY_EXPANSION = <<EOF
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE member [
|
||||||
|
<!ENTITY a "a">
|
||||||
|
<!ENTITY a2 "&a; &a;">
|
||||||
|
]>
|
||||||
|
<member>
|
||||||
|
&a;
|
||||||
|
&a2;
|
||||||
|
</member>
|
||||||
|
EOF
|
||||||
|
|
||||||
|
def test_entity_expansion_limit
|
||||||
|
doc = REXML::Document.new(XML_WITH_NESTED_ENTITY)
|
||||||
|
assert_raise(RuntimeError) do
|
||||||
|
doc.root.children.first.value
|
||||||
|
end
|
||||||
|
REXML::Document.entity_expansion_limit = 100
|
||||||
|
assert_equal(100, REXML::Document.entity_expansion_limit)
|
||||||
|
doc = REXML::Document.new(XML_WITH_NESTED_ENTITY)
|
||||||
|
assert_raise(RuntimeError) do
|
||||||
|
doc.root.children.first.value
|
||||||
|
end
|
||||||
|
assert_equal(101, doc.entity_expansion_count)
|
||||||
|
|
||||||
|
REXML::Document.entity_expansion_limit = 4
|
||||||
|
doc = REXML::Document.new(XML_WITH_4_ENTITY_EXPANSION)
|
||||||
|
assert_equal("\na\na a\n", doc.root.children.first.value)
|
||||||
|
REXML::Document.entity_expansion_limit = 3
|
||||||
|
doc = REXML::Document.new(XML_WITH_4_ENTITY_EXPANSION)
|
||||||
|
assert_raise(RuntimeError) do
|
||||||
|
doc.root.children.first.value
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
REXML::Document.entity_expansion_limit = 10000
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
#define RUBY_VERSION "1.8.7"
|
#define RUBY_VERSION "1.8.7"
|
||||||
#define RUBY_RELEASE_DATE "2009-01-22"
|
#define RUBY_RELEASE_DATE "2009-01-23"
|
||||||
#define RUBY_VERSION_CODE 187
|
#define RUBY_VERSION_CODE 187
|
||||||
#define RUBY_RELEASE_CODE 20090122
|
#define RUBY_RELEASE_CODE 20090123
|
||||||
#define RUBY_PATCHLEVEL 92
|
#define RUBY_PATCHLEVEL 93
|
||||||
|
|
||||||
#define RUBY_VERSION_MAJOR 1
|
#define RUBY_VERSION_MAJOR 1
|
||||||
#define RUBY_VERSION_MINOR 8
|
#define RUBY_VERSION_MINOR 8
|
||||||
#define RUBY_VERSION_TEENY 7
|
#define RUBY_VERSION_TEENY 7
|
||||||
#define RUBY_RELEASE_YEAR 2009
|
#define RUBY_RELEASE_YEAR 2009
|
||||||
#define RUBY_RELEASE_MONTH 1
|
#define RUBY_RELEASE_MONTH 1
|
||||||
#define RUBY_RELEASE_DAY 22
|
#define RUBY_RELEASE_DAY 23
|
||||||
|
|
||||||
#ifdef RUBY_EXTERN
|
#ifdef RUBY_EXTERN
|
||||||
RUBY_EXTERN const char ruby_version[];
|
RUBY_EXTERN const char ruby_version[];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue