Skip to content

Commit d9355e3

Browse files
committed
internal/parser: prevent infinite loop in value parsing
This should do some backtracking later, but let's fix the loop for now.
1 parent e840173 commit d9355e3

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

esbuildplugin/plugin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package esbuildplugin
22

33
import (
4+
"context"
5+
"runtime/pprof"
6+
47
"github.com/evanw/esbuild/pkg/api"
58
"github.com/samsarahq/go/oops"
69
"github.com/stephen/cssc"
@@ -86,6 +89,7 @@ func Plugin(opts ...Option) api.Plugin {
8689
options = opt(options)
8790
}
8891

92+
pprof.SetGoroutineLabels(pprof.WithLabels(context.TODO(), pprof.Labels("cssc-path", args.Path)))
8993
result := cssc.Compile(options)
9094

9195
if len(errors) > 0 {

internal/parser/parser.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,13 @@ func (p *parser) parseValue() ast.Value {
408408
fn.Arguments = append(fn.Arguments, p.parseMathExpression())
409409
continue
410410
}
411-
fn.Arguments = append(fn.Arguments, p.parseValue())
411+
val := p.parseValue()
412+
if val == nil {
413+
// XXX: there's probably some backtracking to do here?
414+
break arguments
415+
}
416+
417+
fn.Arguments = append(fn.Arguments, val)
412418
}
413419
}
414420

0 commit comments

Comments
 (0)