From d40e35a87257cd1cabe9ac71dc8cca744c242822 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 9 Jan 2024 13:39:49 +0200 Subject: [PATCH 1/2] early checks --- vmhost/contexts/runtime.go | 4 ++++ vmhost/contexts/validator.go | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/vmhost/contexts/runtime.go b/vmhost/contexts/runtime.go index f2da057d8..be17ab097 100644 --- a/vmhost/contexts/runtime.go +++ b/vmhost/contexts/runtime.go @@ -789,6 +789,10 @@ func (context *runtimeContext) CountSameContractInstancesOnStack(address []byte) // FunctionNameChecked returns the function name, after checking that it exists in the contract. func (context *runtimeContext) FunctionNameChecked() (string, error) { functionName := context.FunctionName() + err := verifyCallFunction(functionName) + if err != nil { + return "", executor.ErrFuncNotFound + } if context.HasFunction(functionName) { return functionName, nil } diff --git a/vmhost/contexts/validator.go b/vmhost/contexts/validator.go index 3cd1ee137..c3d3c636e 100644 --- a/vmhost/contexts/validator.go +++ b/vmhost/contexts/validator.go @@ -62,6 +62,20 @@ func (validator *wasmValidator) verifyProtectedFunctions(instance executor.Insta } func (validator *wasmValidator) verifyValidFunctionName(functionName string) error { + err := verifyCallFunction(functionName) + if err != nil { + return err + } + + errInvalidName := fmt.Errorf("%w: %s", vmhost.ErrInvalidFunctionName, functionName) + if validator.reserved.IsReserved(functionName) { + return errInvalidName + } + + return nil +} + +func verifyCallFunction(functionName string) error { const maxLengthOfFunctionName = 256 errInvalidName := fmt.Errorf("%w: %s", vmhost.ErrInvalidFunctionName, functionName) @@ -78,9 +92,6 @@ func (validator *wasmValidator) verifyValidFunctionName(functionName string) err if !validCharactersOnly(functionName) { return errInvalidName } - if validator.reserved.IsReserved(functionName) { - return errInvalidName - } return nil } From b7fa5b5a10e18e997133007235d2bf75ecd1d06f Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 9 Jan 2024 13:58:04 +0200 Subject: [PATCH 2/2] fix after comment --- vmhost/contexts/validator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vmhost/contexts/validator.go b/vmhost/contexts/validator.go index c3d3c636e..33114c775 100644 --- a/vmhost/contexts/validator.go +++ b/vmhost/contexts/validator.go @@ -67,7 +67,7 @@ func (validator *wasmValidator) verifyValidFunctionName(functionName string) err return err } - errInvalidName := fmt.Errorf("%w: %s", vmhost.ErrInvalidFunctionName, functionName) + errInvalidName := fmt.Errorf("%w: %x", vmhost.ErrInvalidFunctionName, functionName) if validator.reserved.IsReserved(functionName) { return errInvalidName }