From 8ec556e603ed5c21796409b5b487cbf9bf28751f Mon Sep 17 00:00:00 2001 From: 6h057 <15034695+omarsy@users.noreply.github.com> Date: Wed, 30 Oct 2024 22:56:47 +0100 Subject: [PATCH] fix(gnovm): forbid star expression when value is nil (#3053) close: #3052
Contributors' checklist... - [ ] Added new tests, or not needed, or not feasible - [ ] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [ ] Updated the official documentation or not needed - [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [ ] Added references to related issues and PRs - [ ] Provided any useful hints for running manual tests
--- gnovm/pkg/gnolang/preprocess.go | 3 +++ gnovm/tests/files/ptr10.gno | 8 ++++++++ 2 files changed, 11 insertions(+) create mode 100644 gnovm/tests/files/ptr10.gno diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 10c55979520..a7a1e15bbf3 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -1760,6 +1760,9 @@ func preprocess1(store Store, ctx BlockNode, n Node) Node { // TRANS_LEAVE ----------------------- case *StarExpr: xt := evalStaticTypeOf(store, last, n.X) + if xt == nil { + panic(fmt.Sprintf("invalid operation: cannot indirect nil")) + } if xt.Kind() != PointerKind && xt.Kind() != TypeKind { panic(fmt.Sprintf("invalid operation: cannot indirect %s (variable of type %s)", n.X.String(), xt.String())) } diff --git a/gnovm/tests/files/ptr10.gno b/gnovm/tests/files/ptr10.gno new file mode 100644 index 00000000000..807fc149808 --- /dev/null +++ b/gnovm/tests/files/ptr10.gno @@ -0,0 +1,8 @@ +package main + +func main() { + println(*nil) +} + +// Error: +// main/files/ptr10.gno:4:10: invalid operation: cannot indirect nil