Skip to content

Commit 71641bb

Browse files
committed
Fix segfault caused by empty condition in ternary
Reported by https://hackerone.com/jpenalbae
1 parent a630c4f commit 71641bb

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

mrbgems/mruby-compiler/core/codegen.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,10 @@ codegen(codegen_scope *s, node *tree, int val)
13621362
int pos1, pos2;
13631363
node *e = tree->cdr->cdr->car;
13641364

1365+
if (!tree->car) {
1366+
codegen(s, e, val);
1367+
return;
1368+
}
13651369
switch ((intptr_t)tree->car->car) {
13661370
case NODE_TRUE:
13671371
case NODE_INT:

test/t/codegen.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
##
2+
# Codegen tests
3+
4+
assert('empty condition in ternary expression parses correctly') do
5+
assert_equal () ? 1 : 2, 2
6+
end

0 commit comments

Comments
 (0)