Repository navigation
Conversation
Signed-off-by: Jasur Gulyamov <gulamovzavohir02@gmail.com>
gulamovzavohir02-glitch
temporarily deployed
to
security-review
September 16, 2026 09:33 — with
GitHub Actions
Inactive
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1749 +/- ##
==========================================
+ Coverage 84.88% 84.92% +0.04%
==========================================
Files 110 110
Lines 9055 9063 +8
==========================================
+ Hits 7686 7697 +11
+ Misses 1369 1366 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ccojocar
approved these changes
Sep 16, 2026
cipherprofessor
added a commit
to cipherprofessor/gosec
that referenced
this pull request
Sep 29, 2026
…ices A nil-declared slice's IndexAddr was flagged unconditionally regardless of any surrounding "if len(s) == N" guard, because it's caught by an early, value-based check that never enters the trackSliceBounds/ifs correlation pipeline securego#1746/securego#1749 use to trust an equality guard for make()/literal slices. Same guard shape, inconsistent answer, purely because of how the empty slice was constructed -- verified against master via an SSA dump (nil case resolves to a bare *ssa.Const, the make() case to a *ssa.Slice with a real Alloc, only the latter feeds the existing pipeline). Defer nil-slice-constant accesses instead of flagging them immediately, separately collect "len(nilConst) == N" guards (reusing the existing extractSliceIfLenCondition helper), and resolve each access after its function is fully walked: if the guard's safe (then) successor block dominates the access and the index fits the asserted length, trust it, same as the make() case already does. Keying is by the specific *ssa.Const each len()/access involves, not by type -- verified empirically that Go's SSA builder allocates a distinct constant per nil-typed variable even when the type is identical, so this can't confuse "var a []int" with "var b []int" sharing a type. A guard is only trusted when it's the sole one recorded for its const; multiple guards on the same const fall back to flagging unconditionally, same as before this change. Adds regression coverage for: a nil slice safely covered by a guard, one where the index isn't covered, two distinct same-type nil slices each independently guarded and safe, and two distinct nil slices where only one is guarded (the unguarded one must still fire). Fixes the remaining part of securego#1727 not already covered by securego#1746/securego#1749.
ccojocar
pushed a commit
that referenced
this pull request
Oct 2, 2026
…ices (#1752) A nil-declared slice's IndexAddr was flagged unconditionally regardless of any surrounding "if len(s) == N" guard, because it's caught by an early, value-based check that never enters the trackSliceBounds/ifs correlation pipeline #1746/#1749 use to trust an equality guard for make()/literal slices. Same guard shape, inconsistent answer, purely because of how the empty slice was constructed -- verified against master via an SSA dump (nil case resolves to a bare *ssa.Const, the make() case to a *ssa.Slice with a real Alloc, only the latter feeds the existing pipeline). Defer nil-slice-constant accesses instead of flagging them immediately, separately collect "len(nilConst) == N" guards (reusing the existing extractSliceIfLenCondition helper), and resolve each access after its function is fully walked: if the guard's safe (then) successor block dominates the access and the index fits the asserted length, trust it, same as the make() case already does. Keying is by the specific *ssa.Const each len()/access involves, not by type -- verified empirically that Go's SSA builder allocates a distinct constant per nil-typed variable even when the type is identical, so this can't confuse "var a []int" with "var b []int" sharing a type. A guard is only trusted when it's the sole one recorded for its const; multiple guards on the same const fall back to flagging unconditionally, same as before this change. Adds regression coverage for: a nil slice safely covered by a guard, one where the index isn't covered, two distinct same-type nil slices each independently guarded and safe, and two distinct nil slices where only one is guarded (the unguarded one must still fire). Fixes the remaining part of #1727 not already covered by #1746/#1749.
This branch was previously deployed
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.
Fixes the subslice equality-guard defect noted as out of scope in #1746; related to #1727.
Under
if len(s) == 3, G602 reports safe subslices such ass[:3]ands[1:3]. Conversely, a three-index subslice such ass[:3:3]in theelsebranch can have its finding incorrectly cleared. The existing*ssa.Slicearm compares only the maximum index against the equality constant, ignoring the actual low/high bounds and treating both successors as if equality held.The change checks low, high, and maximum bounds against the asserted length, including constant offsets in the guard, and only clears findings in the equality branch. Omitted low/high bounds use their Go defaults; unknown explicit bounds remain conservative. The implementation reuses the existing three-index bounds predicate and leaves the neighboring index-access logic unchanged.
Validation:
go test ./...go build ./cmd/gosecgolangci-lint run(v2.13.2): 0 issues.-exclude-dir=testdata ./...): 0 findings.This does not claim to resolve the nil-slice or append-tracking cases in #1727. Developed with AI assistance.