Skip to content

Commit

Permalink
Merge pull request SUSE#73 from djoreilly/fix-cronsnoop-panic
Browse files Browse the repository at this point in the history
cronsnoop: fix panic when crontab has empty line
  • Loading branch information
jeffmahoney authored Oct 12, 2023
2 parents 01be570 + cd2efa1 commit 29f92a7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vql/linux/cronsnoop/cron-lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func special_cron_string(line_fields []string) bool {

func should_skip_line(line_fields []string) bool {
// ignore comments and empty lines
if line_fields[0][0] == '#' || len(line_fields) == 0 {
if len(line_fields) == 0 || len(line_fields[0]) == 0 || line_fields[0][0] == '#' {
return true
}

Expand Down
7 changes: 7 additions & 0 deletions vql/linux/cronsnoop/cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,13 @@ func TestMultiUserCommentIgnore(t *testing.T) {
assertMUserDoesntExist("user3", fName, s, t)
}

func TestShouldSkipLineEmptyLine(t *testing.T) {
fields := []string{""}
if !should_skip_line(fields) {
t.Fatal("Empty line should be skipped")
}
}

func TestMultiUserSpecialStringHandling(t *testing.T) {
tempdir := t.TempDir()

Expand Down

0 comments on commit 29f92a7

Please sign in to comment.