Skip to content

Commit 29f92a7

Browse files
authored
Merge pull request SUSE#73 from djoreilly/fix-cronsnoop-panic
cronsnoop: fix panic when crontab has empty line
2 parents 01be570 + cd2efa1 commit 29f92a7

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

vql/linux/cronsnoop/cron-lib.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func special_cron_string(line_fields []string) bool {
203203

204204
func should_skip_line(line_fields []string) bool {
205205
// ignore comments and empty lines
206-
if line_fields[0][0] == '#' || len(line_fields) == 0 {
206+
if len(line_fields) == 0 || len(line_fields[0]) == 0 || line_fields[0][0] == '#' {
207207
return true
208208
}
209209

vql/linux/cronsnoop/cron_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,13 @@ func TestMultiUserCommentIgnore(t *testing.T) {
367367
assertMUserDoesntExist("user3", fName, s, t)
368368
}
369369

370+
func TestShouldSkipLineEmptyLine(t *testing.T) {
371+
fields := []string{""}
372+
if !should_skip_line(fields) {
373+
t.Fatal("Empty line should be skipped")
374+
}
375+
}
376+
370377
func TestMultiUserSpecialStringHandling(t *testing.T) {
371378
tempdir := t.TempDir()
372379

0 commit comments

Comments
 (0)