Skip to content

Commit 6a250d2

Browse files
koumame
authored andcommitted
Fix a bug that invalid element start may be accepted
HackerOne: HO-1104077 It's caused by ignoring garbage before "\n<NAME...". Reported by Juho Nurminen. Thanks!!!
1 parent 2fe62e2 commit 6a250d2

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/rexml/parsers/baseparser.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class BaseParser
6161
XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>/um
6262
INSTRUCTION_START = /\A<\?/u
6363
INSTRUCTION_PATTERN = /<\?#{NAME}(\s+.*?)?\?>/um
64-
TAG_MATCH = /^<((?>#{QNAME_STR}))/um
64+
TAG_MATCH = /\A<((?>#{QNAME_STR}))/um
6565
CLOSE_MATCH = /^\s*<\/(#{QNAME_STR})\s*>/um
6666

6767
VERSION = /\bversion\s*=\s*["'](.*?)['"]/um

test/parse/test_element.rb

+13
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ def test_empty_namespace_attribute_name
4646
4747
DETAIL
4848
end
49+
50+
def test_garbage_less_than_before_root_element_at_line_start
51+
exception = assert_raise(REXML::ParseException) do
52+
parse("<\n<x/>")
53+
end
54+
assert_equal(<<-DETAIL.chomp, exception.to_s)
55+
malformed XML: missing tag start
56+
Line: 2
57+
Position: 6
58+
Last 80 unconsumed characters:
59+
< <x/>
60+
DETAIL
61+
end
4962
end
5063
end
5164
end

0 commit comments

Comments
 (0)