Skip to content

Commit ebfc98d

Browse files
authored
chore: move guards to satisfy CodeQL (coder#19600)
1 parent 4376586 commit ebfc98d

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

site/site.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,16 +1018,6 @@ func newBinMetadataCache(binFS http.FileSystem, binSha1Hashes map[string]string)
10181018
}
10191019

10201020
func (b *binMetadataCache) getMetadata(name string) (binMetadata, error) {
1021-
// Reject any invalid or non-basename paths before touching the filesystem.
1022-
if name == "" ||
1023-
name == "." ||
1024-
strings.Contains(name, "/") ||
1025-
strings.Contains(name, "\\") ||
1026-
!fs.ValidPath(name) ||
1027-
path.Base(name) != name {
1028-
return binMetadata{}, os.ErrNotExist
1029-
}
1030-
10311021
b.mut.RLock()
10321022
metadata, ok := b.metadata[name]
10331023
b.mut.RUnlock()
@@ -1040,6 +1030,16 @@ func (b *binMetadataCache) getMetadata(name string) (binMetadata, error) {
10401030
b.sem <- struct{}{}
10411031
defer func() { <-b.sem }()
10421032

1033+
// Reject any invalid or non-basename paths before touching the filesystem.
1034+
if name == "" ||
1035+
name == "." ||
1036+
strings.Contains(name, "/") ||
1037+
strings.Contains(name, "\\") ||
1038+
!fs.ValidPath(name) ||
1039+
path.Base(name) != name {
1040+
return binMetadata{}, os.ErrNotExist
1041+
}
1042+
10431043
f, err := b.binFS.Open(name)
10441044
if err != nil {
10451045
return binMetadata{}, err

0 commit comments

Comments
 (0)