summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/d5/tengo/compiler/compiler.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2019-03-05 23:08:54 +0100
committerWim <wim@42.be>2019-03-05 23:10:45 +0100
commit325d62b41c03f0530513a4f404cc8d7349b6885b (patch)
treed6f9f2809bdcd3a35b696b412c24cf6f54ddab78 /vendor/github.com/d5/tengo/compiler/compiler.go
parente955a056e2aa4a07c6375315113886b2ee86138c (diff)
downloadmatterbridge-msglm-325d62b41c03f0530513a4f404cc8d7349b6885b.tar.gz
matterbridge-msglm-325d62b41c03f0530513a4f404cc8d7349b6885b.tar.bz2
matterbridge-msglm-325d62b41c03f0530513a4f404cc8d7349b6885b.zip
Update vendor d5/tengo
Diffstat (limited to 'vendor/github.com/d5/tengo/compiler/compiler.go')
-rw-r--r--vendor/github.com/d5/tengo/compiler/compiler.go24
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(),