Skip to content

Fix use-after-free for Array#<=> - #6340

Merged
matz merged 1 commit into
mruby:masterfrom
dearblue:array-cmp
Sep 17, 2024
Merged

Fix use-after-free for Array#<=>#6340
matz merged 1 commit into
mruby:masterfrom
dearblue:array-cmp

Conversation

@dearblue

@dearblue dearblue commented Sep 3, 2024

Copy link
Copy Markdown
Contributor

The mrb_ary_cmp() function calls mrb_cmp() for comparison, but mrb_cmp() may call the obj.<=> method internally.
If a user-defined <=> method is called and the array object under comparison is expanded or reduced, a reference to an invalid address may subsequently be made.


% bin/mruby -e 'class C; def <=>(other); $array.clear; 0; end; end; $array = Array.new(5) { C.new };  $array <=> $array.dup'
zsh: segmentation fault (core dumped)  ../bin/mruby -e

The `mrb_ary_cmp()` function calls `mrb_cmp()` for comparison, but `mrb_cmp()` may call the `obj.<=>` method internally.
If a user-defined `<=>` method is called and the array object under comparison is expanded or reduced, a reference to an invalid address may subsequently be made.
@dearblue
dearblue requested a review from matz as a code owner September 3, 2024 12:56
@github-actions github-actions Bot added the core label Sep 3, 2024
@matz
matz merged commit 4b500eb into mruby:master Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants