From 850182caf3040ca06a590900918fed9c15eb9028 Mon Sep 17 00:00:00 2001
From: 6h057 <15034695+omarsy@users.noreply.github.com>
Date: Wed, 30 Oct 2024 21:15:34 +0100
Subject: [PATCH] fix(gnovm): forbid star expression when value is not a
pointer (#2984)
closes: #1088
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 | 7 ++++++-
gnovm/tests/files/ptr9.gno | 9 +++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
create mode 100644 gnovm/tests/files/ptr9.gno
diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go
index 2d65dfa5cb1..10c55979520 100644
--- a/gnovm/pkg/gnolang/preprocess.go
+++ b/gnovm/pkg/gnolang/preprocess.go
@@ -1757,7 +1757,12 @@ func preprocess1(store Store, ctx BlockNode, n Node) Node {
case *KeyValueExpr:
// NOTE: For simplicity we just
// use the *CompositeLitExpr.
-
+ // TRANS_LEAVE -----------------------
+ case *StarExpr:
+ xt := evalStaticTypeOf(store, last, n.X)
+ if xt.Kind() != PointerKind && xt.Kind() != TypeKind {
+ panic(fmt.Sprintf("invalid operation: cannot indirect %s (variable of type %s)", n.X.String(), xt.String()))
+ }
// TRANS_LEAVE -----------------------
case *SelectorExpr:
xt := evalStaticTypeOf(store, last, n.X)
diff --git a/gnovm/tests/files/ptr9.gno b/gnovm/tests/files/ptr9.gno
new file mode 100644
index 00000000000..6e104942d81
--- /dev/null
+++ b/gnovm/tests/files/ptr9.gno
@@ -0,0 +1,9 @@
+package main
+
+func main() {
+ v := 1
+ println(*v)
+}
+
+// Error:
+// main/files/ptr9.gno:5:10: invalid operation: cannot indirect v (variable of type int)