diff options
Diffstat (limited to 'vendor/github.com/d5/tengo/compiler/compiler.go')
-rw-r--r-- | vendor/github.com/d5/tengo/compiler/compiler.go | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/vendor/github.com/d5/tengo/compiler/compiler.go b/vendor/github.com/d5/tengo/compiler/compiler.go index 141ea8fd..d8bc05fd 100644 --- a/vendor/github.com/d5/tengo/compiler/compiler.go +++ b/vendor/github.com/d5/tengo/compiler/compiler.go @@ -5,11 +5,11 @@ import ( "io" "reflect" + "github.com/d5/tengo" "github.com/d5/tengo/compiler/ast" "github.com/d5/tengo/compiler/source" "github.com/d5/tengo/compiler/token" "github.com/d5/tengo/objects" - "github.com/d5/tengo/stdlib" ) // Compiler compiles the AST into a bytecode. @@ -54,9 +54,6 @@ func NewCompiler(file *source.File, symbolTable *SymbolTable, constants []object // builtin modules if builtinModules == nil { builtinModules = make(map[string]bool) - for name := range stdlib.Modules { - builtinModules[name] = true - } } return &Compiler{ @@ -195,6 +192,10 @@ func (c *Compiler) Compile(node ast.Node) error { } case *ast.StringLit: + if len(node.Value) > tengo.MaxStringLen { + return c.error(node, objects.ErrStringLimit) + } + c.emit(node, OpConstant, c.addConstant(&objects.String{Value: node.Value})) case *ast.CharLit: @@ -332,6 +333,9 @@ func (c *Compiler) Compile(node ast.Node) error { case *ast.MapLit: for _, elt := range node.Elements { // key + if len(elt.Key) > tengo.MaxStringLen { + return c.error(node, objects.ErrStringLimit) + } c.emit(node, OpConstant, c.addConstant(&objects.String{Value: elt.Key})) // value @@ -507,6 +511,10 @@ func (c *Compiler) Compile(node ast.Node) error { case *ast.ImportExpr: if c.builtinModules[node.ModuleName] { + if len(node.ModuleName) > tengo.MaxStringLen { + return c.error(node, objects.ErrStringLimit) + } + c.emit(node, OpConstant, c.addConstant(&objects.String{Value: node.ModuleName})) c.emit(node, OpGetBuiltinModule) } else { @@ -610,6 +618,14 @@ func (c *Compiler) fork(file *source.File, moduleName string, symbolTable *Symbo return child } +func (c *Compiler) error(node ast.Node, err error) error { + return &Error{ + fileSet: c.file.Set(), + node: node, + error: err, + } +} + func (c *Compiler) errorf(node ast.Node, format string, args ...interface{}) error { return &Error{ fileSet: c.file.Set(), |