Skip to content

Commit 964427f

Browse files
fbogsanybouk
authored andcommitted
Fix unsafe peephole optimization
Reported by https://hackerone.com/dkasak
1 parent a630c4f commit 964427f

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Diff for: mrbgems/mruby-compiler/core/codegen.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -1798,8 +1798,10 @@ codegen(codegen_scope *s, node *tree, int val)
17981798
int pos;
17991799

18001800
pop();
1801-
if (val && vsp >= 0) {
1802-
genop(s, MKOP_AB(OP_MOVE, vsp, cursp()));
1801+
if (val) {
1802+
if (vsp >= 0) {
1803+
genop(s, MKOP_AB(OP_MOVE, vsp, cursp()));
1804+
}
18031805
pos = genop(s, MKOP_AsBx(name[0]=='|'?OP_JMPIF:OP_JMPNOT, cursp(), 0));
18041806
}
18051807
else {

Diff for: test/t/codegen.rb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
##
2+
# Codegen tests
3+
4+
assert('peephole optimization does not eliminate move whose result is reused') do
5+
assert_raise LocalJumpError do
6+
def method
7+
yield
8+
end
9+
method(&a &&= 0)
10+
end
11+
end

0 commit comments

Comments
 (0)