Skip to content

Commit 087698e

Browse files
committed
Add error handling for invalid if condition and test for crash with null byte
1 parent 738da0b commit 087698e

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

expr_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,6 +2683,12 @@ func TestExpr_crash(t *testing.T) {
26832683
require.Error(t, err)
26842684
}
26852685

2686+
func TestExpr_crash_with_zero(t *testing.T) {
2687+
code := "if\x00"
2688+
_, err := expr.Compile(code)
2689+
require.Error(t, err)
2690+
}
2691+
26862692
func TestExpr_nil_op_str(t *testing.T) {
26872693
// Let's test operators, which do `.(string)` in VM, also check for nil.
26882694

parser/parser.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@ func (p *Parser) parseVariableDeclaration() Node {
329329

330330
func (p *Parser) parseConditionalIf() Node {
331331
p.next()
332+
if p.err != nil {
333+
return nil
334+
}
332335
nodeCondition := p.parseExpression(0)
333336
p.expect(Bracket, "{")
334337
expr1 := p.parseSequenceExpression()

0 commit comments

Comments
 (0)