mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-24 14:25:02 +02:00
refactor: prevent out-of-bounds read (#39936)
`IsReadmeFileExtension("readme", exts...)` panicked with `index out of
range [6] with length 6` when `exts` had no empty extension. The only
caller always passes one, so this was not reachable in practice.
Fixes:
https://github.com/go-gitea/gitea/security/quality/rules/go%2Findex-out-of-bounds
Written by Claude.
This commit is contained in:
1 parent
5f8f625ff7
commit
facc0f2b15
2 files changed
+5
-1
No files matched your search
@@ -360,7 +360,7 @@ func IsReadmeFileExtension(name string, ext ...string) (int, bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if name[6] == '.' {
|
if len(name) > 6 && name[6] == '.' {
|
||||||
return len(ext), true
|
return len(ext), true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -142,6 +142,10 @@ func TestMisc_IsReadmeFileName(t *testing.T) {
|
|||||||
assert.Equal(t, testCase.expected, ok)
|
assert.Equal(t, testCase.expected, ok)
|
||||||
assert.Equal(t, testCase.idx, idx)
|
assert.Equal(t, testCase.idx, idx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
idx, ok := IsReadmeFileExtension("readme", ".md")
|
||||||
|
assert.False(t, ok)
|
||||||
|
assert.Zero(t, idx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCleanPath(t *testing.T) {
|
func TestCleanPath(t *testing.T) {
|
||||||
|
|||||||
Reference in new issue
Block a user