-
-
Notifications
You must be signed in to change notification settings - Fork 663
check nil slices, partially check bounds #1396
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
Conversation
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.
Thank you for contributing this fix. Please add some tests in the rule test file to cover this use case https://github.com/securego/gosec/blob/master/testutils/g602_samples.go.
analyzers/slice_bounds.go
Outdated
| case *ssa.Store: // check store to nil slice or out of bounds | ||
| case *ssa.IndexAddr: | ||
| if constantValue, ok := instr.X.(*ssa.Const); ok && constantValue.Type().String()[:2] == "[]" { | ||
| if constantValue.Value == nil { |
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.
Shouldn't this check be placed before accessing the .Type()? What happens if is already nil?
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.
The code assumes that someone will continue to search for errors. For example, when var a [5]int this const value not nil, in this case the simplest error is determined when instead of append(a,...) index assignment is used.
analyzers/slice_bounds.go
Outdated
| } | ||
| case *ssa.Store: // check store to nil slice or out of bounds | ||
| case *ssa.IndexAddr: | ||
| if constantValue, ok := instr.X.(*ssa.Const); ok && constantValue.Type().String()[:2] == "[]" { |
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.
Can the type length be less than 2 under any circumstances?
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.
if type name string less then []*, then this is not slice in this case
|
@ccojocar review please |
|
There are some lint warnings which need to be fixed before merging, otherwise LGTM. |
|
It seems that there is a test failure. |
|
There are still some issues when the gosec built from this pull request. PTAL. Thanks |
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1396 +/- ##
==========================================
- Coverage 68.49% 63.01% -5.49%
==========================================
Files 75 76 +1
Lines 4384 5443 +1059
==========================================
+ Hits 3003 3430 +427
- Misses 1233 1878 +645
+ Partials 148 135 -13 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
fix #1392 partially