Repository navigation
analyzer: fix nil deref in -output=package with a custom capability map - #325
Open
rootkiller6788 wants to merge 2 commits into
Open
rootkiller6788 wants to merge 2 commits into
rootkiller6788 wants to merge 2 commits into
Conversation
added 2 commits
September 14, 2026 20:58
The package output mode uses capabilityInfo.Capability.String() as the map key. Capability is the enum field, and it stays unset when the capability name comes from a user-supplied capability map and isn't one of the Capability values, so oldCapability returns nil and String() dereferences it. Any capability map that defines its own capability name reproduces it. Use GetCapabilityName() instead, which is what the other output modes and the diff tooling already use.
… map Runs capslock over testpkgs/callos with a map that gives os.Getpid a capability name that isn't in the Capability enum, and checks that the package output reports it for that package. This panicked before the previous commit.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
rootkiller6788
marked this pull request as ready for review
November 25, 2026 07:35
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.
-output=packagecrashes when the capability map defines its own capability name:The package output builds its map with
capabilityInfo.Capability.String().Capabilityis the enum field, and it stays unset for a capability name that comes from the user's map and isn't in the enum, sooldCapabilityreturns nil there - and sinceString()has a value receiver, calling it on the nil pointer blows up. Capability maps that only use enum names are fine, which is probably why this went unnoticed.Nothing else in the tree reads the enum field directly:
compare.goandcapslock-git-diffboth key off the capability name, so I did the same here and hoisted it out of the loop while I was at it (it was being computed twice). No behaviour change for capabilities that do have an enum value.Added a test in
testing/that writes a map withfunc os.Getpid TESTCAP, runs capslock overtestpkgs/calloswith-output=package, and checks TESTCAP is reported for that package. It panics without the fix.go vetis clean andgo test ./analyzer/... ./interesting/... ./testing/...passes here, though I have to run it with-p 1/GOMAXPROCS=1on this machine - a couple of the tests intesting/fail on the unmodified tree too when memory gets tight.