fix: track nil flows through function variables#388
Open
yd-beep wants to merge 1 commit intouber-go:mainfrom
Open
fix: track nil flows through function variables#388yd-beep wants to merge 1 commit intouber-go:mainfrom
yd-beep wants to merge 1 commit intouber-go:mainfrom
Conversation
Previously, nilaway would skip nil analysis for calls made through function variables (e.g., `var ProcessFunc = process; ProcessFunc(nil)`), treating them as trusted non-nil. This caused false negatives where nil pointer dereferences were not detected. This change adds support for resolving function variables to their underlying function declarations, enabling proper nil flow tracking through both return values and arguments. Changes: - Add resolveFuncVariable() helper to resolve function variables to their underlying *types.Func for both package-level declarations (var F = f) and local assignments (f := someFunc) - Update ParseExprAsProducer() to use resolved functions for return value analysis when calling through function variables - Update AddComputation() to use resolved functions for argument consumption tracking when calling through function variables - Add getFuncReturnProducersForFunc() to support direct *types.Func usage without requiring an *ast.Ident - Add integration tests for function variable nil tracking If resolution fails (dynamic assignment, closures, etc.), the code falls back to the previous trusted behavior to avoid false positives. Fixes uber-go#387
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #388 +/- ##
==========================================
- Coverage 87.01% 87.01% -0.01%
==========================================
Files 73 73
Lines 8305 8340 +35
==========================================
+ Hits 7227 7257 +30
- Misses 885 888 +3
- Partials 193 195 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, nilaway would skip nil analysis for calls made through function variables (e.g.,
var ProcessFunc = process; ProcessFunc(nil)), treating them as trusted non-nil. This caused false negatives where nil pointer dereferences were not detected.This change adds support for resolving function variables to their underlying function declarations, enabling proper nil flow tracking through both return values and arguments.
Changes:
If resolution fails (dynamic assignment, closures, etc.), the code falls back to the previous trusted behavior to avoid false positives.
Fixes #387