Skip to content

Commit

Permalink
[CWS] fix panic on empty dirname (#10986) (#10991)
Browse files Browse the repository at this point in the history
(cherry picked from commit 0be2d78)

Co-authored-by: Paul Cacheux <paul.cacheux@datadoghq.com>
  • Loading branch information
lebauce and paulcacheux authored Feb 18, 2022
1 parent 5332062 commit b753005
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/security/probe/discarders.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ var (

// use a faster version of path.Dir which adds some sanity checks not required here
func dirname(filename string) string {
if len(filename) == 0 {
return "/"
}

i := len(filename) - 1
for i >= 0 && filename[i] != '/' {
i--
Expand All @@ -238,7 +242,7 @@ func dirname(filename string) string {
return filename
}

if i == 0 {
if i <= 0 {
return "/"
}

Expand Down

0 comments on commit b753005

Please sign in to comment.