Skip to content

Commit

Permalink
fix: applications exec parsing causing out of bounds panic
Browse files Browse the repository at this point in the history
  • Loading branch information
abenz1267 committed Jan 18, 2025
1 parent d264a9e commit a05e69b
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions internal/modules/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (

const ApplicationsName = "applications"

var fieldCodes = []string{"%f", "%F", "%u", "%U", "%d", "%D", "%n", "%N", "%i", "%c", "%k", "%v", "%m"}

type Applications struct {
config config.Applications
mu sync.Mutex
Expand Down Expand Up @@ -613,21 +615,15 @@ func parseExec(execLine string) ([]string, error) {
appendCurrent()

// Remove field codes
// List of field codes: %f %F %u %U %d %D %n %N %i %c %k %v %m
for i, part := range parts {
// Skip the first part (command name)
if i == 0 {
continue
}
for k, v := range parts {
if len(v) == 2 && slices.Contains(fieldCodes, v) {
until := k + 1

// Remove any field codes
if strings.HasPrefix(part, "%") && len(part) == 2 {
switch part[1] {
case 'f', 'F', 'u', 'U', 'd', 'D', 'n', 'N', 'i', 'c', 'k', 'v', 'm':
// Remove this field code
parts = append(parts[:i], parts[i+1:]...)
i-- // Adjust index after removal
if until > len(parts) {
until = len(parts)
}

parts = slices.Delete(parts, k, until)
}
}

Expand Down

0 comments on commit a05e69b

Please sign in to comment.