go-vise

Constrained Size Output Virtual Machine
Info | Log | Files | Refs | README | LICENSE

commit 397985f1ae421a7facd0e83b4261eaa5c91c1729
parent 2989b23b93bd21ab5fe7e37b8a38950a886d07e8
Author: lash <dev@holbrook.no>
Date:   Thu,  6 Apr 2023 12:47:09 +0100

Add descriptive input checker error

Diffstat:
Mgo/engine/engine.go | 9++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/go/engine/engine.go b/go/engine/engine.go @@ -13,7 +13,8 @@ import ( ) var ( - inputRegex = regexp.MustCompile("^[a-zA-Z0-9].*$") + inputRegexStr = "^[a-zA-Z0-9].*$" + inputRegex = regexp.MustCompile(inputRegexStr) ) // //type Config struct { @@ -50,9 +51,10 @@ func(en *Engine) Init(sym string, ctx context.Context) error { return nil } +// return descriptive error if client input is invalid func checkInput(input []byte) error { if !inputRegex.Match(input) { - return fmt.Errorf("Invalid input format: %s", input) + return fmt.Errorf("Input '%s' does not match format /%s/", input, inputRegexStr) } return nil } @@ -70,12 +72,13 @@ func checkInput(input []byte) error { func (en *Engine) Exec(input []byte, ctx context.Context) (bool, error) { err := checkInput(input) if err != nil { - return false, err + return true, err } err = en.st.SetInput(input) if err != nil { return false, err } + log.Printf("new execution with input '%s' (0x%x)", input, input) code, err := en.st.GetCode() if err != nil {