Skip to content

Commit

Permalink
added validation for some regex patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
pratyush.kumar committed Dec 12, 2024
1 parent 50b60b5 commit 17dc68a
Showing 1 changed file with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ type scraper struct {
handleCountManager handlecount.Manager
}

func validateNames(names []string) bool {
patterns := []string{".*", ".", "[a-z]+", "[a-z]*", "*"}
for _, pattern := range patterns {
re := regexp.MustCompile(pattern)
for _, name := range names {
if re.MatchString(name) {
return false
}
}
}
return true
}

// newGroupProcessScraper creates a Process Scraper
func newGroupProcessScraper(settings receiver.Settings, cfg *Config) (*scraper, error) {
scraper := &scraper{
Expand All @@ -74,15 +87,21 @@ func newGroupProcessScraper(settings receiver.Settings, cfg *Config) (*scraper,

var err error

//for _, gc := range cfg.GroupConfig {
// fs, err := filterset.CreateFilterSet(gc.Names, &gc.Config)
// if err != nil {
// return nil, fmt.Errorf("error creating process exclude filters: %w", err)
// }
// scraper.matchGroupFS[gc.ProcessName] = fs
//}

for _, gc := range cfg.GroupConfig {

if !validateNames(gc.Comm.Names) {
fmt.Printf("Unsupported comm names in group: %s", gc.Comm.Names)
continue
}
if !validateNames(gc.Exe.Names) {
fmt.Printf("Unsupported exe names in group: %s", gc.Exe.Names)
continue
}
if !validateNames(gc.Cmdline.Names) {
fmt.Printf("Unsupported cmdline names in group: %s", gc.Cmdline.Names)
continue
}

scraper.matchGroupFS[gc.ProcessName] = make(map[string]filterset.FilterSet)

if len(gc.Comm.Names) > 0 {
Expand Down

0 comments on commit 17dc68a

Please sign in to comment.