-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(PA-6507) Patch rexml gem for CVE-2024-35176 #868
Closed
shubhamshinde360
wants to merge
1
commit into
puppetlabs:master
from
shubhamshinde360:PA-6507-cve-2024-35176
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
resources/patches/ruby_27/rexml_for_CVE-2024-35176.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
commit e597f07718c27dc4414ad39f121376e53056475a | ||
Author: Shubham Shinde <[email protected]> | ||
Date: Tue Jul 9 19:40:43 2024 +0530 | ||
|
||
Read quoted attributes in chunks (#126) | ||
|
||
|
||
# Conflicts: | ||
# lib/rexml/parsers/baseparser.rb | ||
# lib/rexml/source.rb | ||
|
||
diff --git a/lib/rexml/parsers/baseparser.rb b/lib/rexml/parsers/baseparser.rb | ||
index f76aed0..f0b365d 100644 | ||
--- a/lib/rexml/parsers/baseparser.rb | ||
+++ b/lib/rexml/parsers/baseparser.rb | ||
@@ -518,25 +518,43 @@ module REXML | ||
message = "Missing attribute equal: <#{name}>" | ||
raise REXML::ParseException.new(message, @source) | ||
end | ||
- quote = scanner.scan(/['"]/) | ||
- unless quote | ||
+ unless match = @source.match(/(['"])/, true) | ||
message = "Missing attribute value start quote: <#{name}>" | ||
raise REXML::ParseException.new(message, @source) | ||
end | ||
- unless scanner.scan(/.*#{Regexp.escape(quote)}/um) | ||
- match_data = @source.match(/^(.*?)(\/)?>/um, true) | ||
- if match_data | ||
- scanner << "/" if closed | ||
- scanner << ">" | ||
- scanner << match_data[1] | ||
- scanner.pos = pos | ||
- closed = !match_data[2].nil? | ||
- next | ||
- end | ||
- message = | ||
- "Missing attribute value end quote: <#{name}>: <#{quote}>" | ||
+ quote = match[1] | ||
+ value = @source.read_until(quote) | ||
+ unless value.chomp!(quote) | ||
+ message = "Missing attribute value end quote: <#{name}>: <#{quote}>" | ||
raise REXML::ParseException.new(message, @source) | ||
end | ||
+ @source.match(/\s*/um, true) | ||
+ if prefix == "xmlns" | ||
+ if local_part == "xml" | ||
+ if value != "http://www.w3.org/XML/1998/namespace" | ||
+ msg = "The 'xml' prefix must not be bound to any other namespace "+ | ||
+ "(http://www.w3.org/TR/REC-xml-names/#ns-decl)" | ||
+ raise REXML::ParseException.new( msg, @source, self ) | ||
+ end | ||
+ elsif local_part == "xmlns" | ||
+ msg = "The 'xmlns' prefix must not be declared "+ | ||
+ "(http://www.w3.org/TR/REC-xml-names/#ns-decl)" | ||
+ raise REXML::ParseException.new( msg, @source, self) | ||
+ end | ||
+ curr_ns << local_part | ||
+ elsif prefix | ||
+ prefixes << prefix unless prefix == "xml" | ||
+ end | ||
+ | ||
+ if attributes[name] | ||
+ msg = "Duplicate attribute #{name.inspect}" | ||
+ raise REXML::ParseException.new(msg, @source, self) | ||
+ end | ||
+ | ||
+ attributes[name] = value | ||
+ else | ||
+ message = "Invalid attribute name: <#{@source.buffer.split(%r{[/>\s]}).first}>" | ||
+ raise REXML::ParseException.new(message, @source) | ||
end | ||
name = scanner[1] | ||
prefix = scanner[2] | ||
diff --git a/lib/rexml/source.rb b/lib/rexml/source.rb | ||
index 770aefc..86bf6cf 100644 | ||
--- a/lib/rexml/source.rb | ||
+++ b/lib/rexml/source.rb | ||
@@ -81,7 +81,11 @@ module REXML | ||
rv | ||
end | ||
|
||
- def read | ||
+ def read(term = nil) | ||
+ end | ||
+ | ||
+ def read_until(term) | ||
+ @scanner.scan_until(Regexp.union(term)) or @scanner.rest | ||
end | ||
|
||
def consume( pattern ) | ||
@@ -204,9 +208,9 @@ module REXML | ||
rv | ||
end | ||
|
||
- def read | ||
+ def read(term = nil) | ||
begin | ||
- @buffer << readline | ||
+ @buffer << readline(term) | ||
rescue Exception, NameError | ||
@source = nil | ||
end | ||
@@ -216,6 +220,21 @@ module REXML | ||
match( pattern, true ) | ||
end | ||
|
||
+ def read_until(term) | ||
+ pattern = Regexp.union(term) | ||
+ data = [] | ||
+ begin | ||
+ until str = @scanner.scan_until(pattern) | ||
+ @scanner << readline(term) | ||
+ end | ||
+ rescue EOFError | ||
+ @scanner.rest | ||
+ else | ||
+ read if @scanner.eos? and [email protected]? | ||
+ str | ||
+ end | ||
+ end | ||
+ | ||
def match( pattern, cons=false ) | ||
rv = pattern.match(@buffer) | ||
@buffer = $' if cons and rv | ||
@@ -263,8 +282,8 @@ module REXML | ||
end | ||
|
||
private | ||
- def readline | ||
- str = @source.readline(@line_break) | ||
+ def readline(term = nil) | ||
+ str = @source.readline(term || @line_break) | ||
if @pending_buffer | ||
if str.nil? | ||
str = @pending_buffer |
123 changes: 123 additions & 0 deletions
123
resources/patches/ruby_32/rexml_for_CVE-2024-35176.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
|
||
diff --git a/.bundle/gems/rexml-3.2.5/lib/rexml/source.rb b/.bundle/gems/rexml-3.2.5/lib/rexml/source.rb | ||
index 90b370b..373abcf 100644 | ||
--- a/.bundle/gems/rexml-3.2.5/lib/rexml/source.rb | ||
+++ b/.bundle/gems/rexml-3.2.5/lib/rexml/source.rb | ||
@@ -81,7 +81,11 @@ module REXML | ||
rv | ||
end | ||
|
||
- def read | ||
+ def read(term = nil) | ||
+ end | ||
+ | ||
+ def read_until(term) | ||
+ @scanner.scan_until(Regexp.union(term)) or @scanner.rest | ||
end | ||
|
||
def consume( pattern ) | ||
@@ -204,14 +208,29 @@ module REXML | ||
rv | ||
end | ||
|
||
- def read | ||
+ def read(term = nil) | ||
begin | ||
- @buffer << readline | ||
+ @buffer << readline(term) | ||
rescue Exception, NameError | ||
@source = nil | ||
end | ||
end | ||
|
||
+ def read_until(term) | ||
+ pattern = Regexp.union(term) | ||
+ data = [] | ||
+ begin | ||
+ until str = @scanner.scan_until(pattern) | ||
+ @scanner << readline(term) | ||
+ end | ||
+ rescue EOFError | ||
+ @scanner.rest | ||
+ else | ||
+ read if @scanner.eos? and [email protected]? | ||
+ str | ||
+ end | ||
+ end | ||
+ | ||
def consume( pattern ) | ||
match( pattern, true ) | ||
end | ||
@@ -263,8 +282,8 @@ module REXML | ||
end | ||
|
||
private | ||
- def readline | ||
- str = @source.readline(@line_break) | ||
+ def readline(term = nil) | ||
+ str = @source.readline(term || @line_break) | ||
if @pending_buffer | ||
if str.nil? | ||
str = @pending_buffer | ||
diff --git a/.bundle/gems/rexml-3.2.5/lib/rexml/parsers/baseparser.rb b/.bundle/gems/rexml-3.2.5/lib/rexml/parsers/baseparser.rb | ||
index 305b120..7001bb2 100644 | ||
--- a/.bundle/gems/rexml-3.2.5/lib/rexml/parsers/baseparser.rb | ||
+++ b/.bundle/gems/rexml-3.2.5/lib/rexml/parsers/baseparser.rb | ||
@@ -618,25 +618,43 @@ module REXML | ||
message = "Missing attribute equal: <#{name}>" | ||
raise REXML::ParseException.new(message, @source) | ||
end | ||
- quote = scanner.scan(/['"]/) | ||
- unless quote | ||
+ unless match = @source.match(/(['"])/, true) | ||
message = "Missing attribute value start quote: <#{name}>" | ||
raise REXML::ParseException.new(message, @source) | ||
end | ||
- unless scanner.scan(/.*#{Regexp.escape(quote)}/um) | ||
- match_data = @source.match(/^(.*?)(\/)?>/um, true) | ||
- if match_data | ||
- scanner << "/" if closed | ||
- scanner << ">" | ||
- scanner << match_data[1] | ||
- scanner.pos = pos | ||
- closed = !match_data[2].nil? | ||
- next | ||
- end | ||
- message = | ||
- "Missing attribute value end quote: <#{name}>: <#{quote}>" | ||
+ quote = match[1] | ||
+ value = @source.read_until(quote) | ||
+ unless value.chomp!(quote) | ||
+ message = "Missing attribute value end quote: <#{name}>: <#{quote}>" | ||
raise REXML::ParseException.new(message, @source) | ||
end | ||
+ @source.match(/\s*/um, true) | ||
+ if prefix == "xmlns" | ||
+ if local_part == "xml" | ||
+ if value != "http://www.w3.org/XML/1998/namespace" | ||
+ msg = "The 'xml' prefix must not be bound to any other namespace "+ | ||
+ "(http://www.w3.org/TR/REC-xml-names/#ns-decl)" | ||
+ raise REXML::ParseException.new( msg, @source, self ) | ||
+ end | ||
+ elsif local_part == "xmlns" | ||
+ msg = "The 'xmlns' prefix must not be declared "+ | ||
+ "(http://www.w3.org/TR/REC-xml-names/#ns-decl)" | ||
+ raise REXML::ParseException.new( msg, @source, self) | ||
+ end | ||
+ curr_ns << local_part | ||
+ elsif prefix | ||
+ prefixes << prefix unless prefix == "xml" | ||
+ end | ||
+ | ||
+ if attributes[name] | ||
+ msg = "Duplicate attribute #{name.inspect}" | ||
+ raise REXML::ParseException.new(msg, @source, self) | ||
+ end | ||
+ | ||
+ attributes[name] = value | ||
+ else | ||
+ message = "Invalid attribute name: <#{@source.buffer.split(%r{[/>\s]}).first}>" | ||
+ raise REXML::ParseException.new(message, @source) | ||
end | ||
name = scanner[1] | ||
prefix = scanner[2] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't expect conflicts. Did this occur because you cherry-picked the commit into the ruby 2.7 source tree? Is there a different patch we can use that applies cleanly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @joshcooper,
Yes, I cherry-picked the commit ruby/rexml@4325835 into tag https://github.com/ruby/rexml/releases/tag/v3.2.5 and it conflicted.
Was not able to find other patches to apply cleanly either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had to resolve conflicts manually, is there any other path we can take in such situations?