diff options
| author | Francis Bogsanyi <[email protected]> | 2016-11-17 12:59:27 -0500 |
|---|---|---|
| committer | Bouke van der Bijl <[email protected]> | 2016-11-24 10:32:34 -0500 |
| commit | 964427f82c5a8556daf4448b47cc65fb6d2a94b8 (patch) | |
| tree | d6f3ce9ecaf598b76a70e80e58e5af348a9f51ef | |
| parent | a630c4f413f6af764e68210430e8b61a435d38d7 (diff) | |
| download | mruby-964427f82c5a8556daf4448b47cc65fb6d2a94b8.tar.gz mruby-964427f82c5a8556daf4448b47cc65fb6d2a94b8.zip | |
Fix unsafe peephole optimization
Reported by https://hackerone.com/dkasak
| -rw-r--r-- | mrbgems/mruby-compiler/core/codegen.c | 6 | ||||
| -rw-r--r-- | test/t/codegen.rb | 11 |
2 files changed, 15 insertions, 2 deletions
diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index 0c84dd558..39d62348a 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -1798,8 +1798,10 @@ codegen(codegen_scope *s, node *tree, int val) int pos; pop(); - if (val && vsp >= 0) { - genop(s, MKOP_AB(OP_MOVE, vsp, cursp())); + if (val) { + if (vsp >= 0) { + genop(s, MKOP_AB(OP_MOVE, vsp, cursp())); + } pos = genop(s, MKOP_AsBx(name[0]=='|'?OP_JMPIF:OP_JMPNOT, cursp(), 0)); } else { diff --git a/test/t/codegen.rb b/test/t/codegen.rb new file mode 100644 index 000000000..f910d37fb --- /dev/null +++ b/test/t/codegen.rb @@ -0,0 +1,11 @@ +## +# Codegen tests + +assert('peephole optimization does not eliminate move whose result is reused') do + assert_raise LocalJumpError do + def method + yield + end + method(&a &&= 0) + end +end |
