-
Notifications
You must be signed in to change notification settings - Fork 405
fix: Missing Type Check for Built-in Function Arguments (len, cap) Causes Runtime Panic #3454 #4033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
🛠 PR Checks SummaryAll Automated Checks passed. ✅ Manual Checks (for Reviewers):
Read More🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers. ✅ Automated Checks (for Contributors):🟢 Maintainers must be able to edit this pull request (more info) ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
gnovm/pkg/gnolang/gno_test.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be filetests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will move them there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a first sanity review
gnovm/pkg/gnolang/preprocess.go
Outdated
const ( | ||
BuiltinLen = "len" | ||
BuiltinCap = "cap" | ||
BuiltinMake = "make" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use constant names, so just use the raw strings in the comparison above.
gnovm/pkg/gnolang/preprocess.go
Outdated
@@ -1362,6 +1363,10 @@ func preprocess1(store Store, ctx BlockNode, n Node) Node { | |||
ift := evalStaticTypeOf(store, last, n.Func) | |||
switch cft := baseOf(ift).(type) { | |||
case *FuncType: | |||
fn := extractFunctionName(n) | |||
if fn == BuiltinMake || fn == BuiltinCap || fn == BuiltinLen { | |||
assertValidBuiltinArgType(store, last, n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use evalStaticTypeOf
on each argument.
gnovm/pkg/gnolang/preprocess.go
Outdated
case *ConstExpr: | ||
assertValidBuiltinArgType(store, last, currExpr.Source) | ||
case *NameExpr: | ||
assertValidBuiltinArgType(store, last, currExpr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an infinite loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks okay. Just fix the requested changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a first round review.
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for your work! left some comments please check. Additionally, there's a lack of testing for the new added logic. Please ensure sufficient test coverage.
Invalid arguments provided to builtin functions len,cap and make would compile successfully but it was triggering a runtime panic when executed.
fixes #3454