Skip to content

Commit

Permalink
fix(proctree): limit saved file path length
Browse files Browse the repository at this point in the history
File paths are created by concatting the dentries names from the root to the file, and concattign the file name in the end.
Although each dentry and file name has max length, the entire path has none.
To avoid memorly leakage caused by saving file paths, introduce a limit to the save path length.
  • Loading branch information
AlonZivony committed May 19, 2024
1 parent 3939c77 commit 41ce163
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/proctree/fileinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,19 @@ func (fi *FileInfo) SetFeedAt(feed FileInfoFeed, targetTime time.Time) {
fi.setFeedAt(feed, targetTime)
}

// Paths theoretically has no limit, but we do need to set a limit for the sake of
// managing memory more responsibly.
const MaxPathLen = 1024

func (fi *FileInfo) setFeedAt(feed FileInfoFeed, targetTime time.Time) {
if feed.Path != "" {
fi.path.Set(feed.Path, targetTime)
filePath := feed.Path
if len(filePath) > MaxPathLen {
// Take only the end of the path, as the specific file name and location are the most
// important parts.
filePath = filePath[len(filePath)-MaxPathLen:]
}
fi.path.Set(filePath, targetTime)
}
if feed.Dev >= 0 {
fi.dev.Set(feed.Dev, targetTime)
Expand Down

0 comments on commit 41ce163

Please sign in to comment.