Skip to content

Fix use-after-free in String#strip methods - #18920

Merged
peterzhu2118 merged 1 commit into
ruby:masterfrom
peterzhu2118:str-strip-uaf
Sep 19, 2026
Merged

peterzhu2118 merged 1 commit into
ruby:masterfrom
peterzhu2118:str-strip-uaf

Conversation

@peterzhu2118

Copy link
Copy Markdown
Member

The selector conversion may run aribtrary Ruby code and modify the source string. This can cause a use-after-free if it resizes the source string. For example, the following script causes corruption:

s = "-" * 1000 + "abc" + "-" * 1000
obj = Object.new
obj.define_singleton_method(:to_str) do
  s.clear
  "-"
end
p s.strip(obj)

The selector conversion may run aribtrary Ruby code and modify the source
string. This can cause a use-after-free if it resizes the source string.
For example, the following script causes corruption:

    s = "-" * 1000 + "abc" + "-" * 1000
    obj = Object.new
    obj.define_singleton_method(:to_str) do
      s.clear
      "-"
    end
    p s.strip(obj)
@peterzhu2118
peterzhu2118 merged commit 44874b7 into ruby:master Sep 19, 2026
140 of 142 checks passed
@peterzhu2118
peterzhu2118 deleted the str-strip-uaf branch September 19, 2026 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant