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..33114c775 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: %x", 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 }