Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions chkcrontab_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
FILE_RE_WHITELIST = [re.compile(x) for x in
(r'\.in$', r'\.cron$', r'\.disabled$', r'^(\S+\.)?cron\.d$')]

# Per https://manpages.debian.org/jessie/cron/crontab.5.en.html:
# "The maximum permitted length for the command field is 998 characters."
MAX_COMMAND_LENGTH = 998

class FSM(object):
"""Finite State Machine.
Expand Down Expand Up @@ -738,6 +741,9 @@ def ValidateAndLog(self, log):
log.LineWarn(log.MSG_BARE_PERCENT, 'A bare % is a line break in'
' crontab and is commonly not intended.')

if len(self.command) > MAX_COMMAND_LENGTH:
log.LineError(log.MSG_COMMAND_LENGTH_ERROR, 'Command length is %d which is greater'
' than %d (max allowed characters)' % (len(self.command), MAX_COMMAND_LENGTH))

class CronLineAt(CronLineTimeAction):
"""For cron lines specified with @ time specs."""
Expand Down Expand Up @@ -885,6 +891,7 @@ class LogCounter(object):

_msg_kinds = set(('BARE_PERCENT',
'CHKCRONTAB_ERROR',
'COMMAND_LENGTH_ERROR',
'FIELD_PARSE_ERROR',
'FIELD_VALUE_ERROR',
'INVALID_AT',
Expand Down
2 changes: 2 additions & 0 deletions tests/test_crontab
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ OK_SPACE=" "
@monthly root Good @ Command
# FAIL 1 for bad time spec.
@m0nthly root Bad @ Command
# FAIL 1 for command too long
0 21 * * wed root /bin/bash/myscript "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"