Bug 253699 - cron: Fix options parsing in system crontabs.
Summary: cron: Fix options parsing in system crontabs.
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Oleksandr Tymoshenko
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-02-19 18:23 UTC by eborisch+FreeBSD
Modified: 2021-06-05 23:58 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description eborisch+FreeBSD 2021-02-19 18:23:20 UTC
Pull request up on GitHub; comment copied here.

https://github.com/freebsd/freebsd-src/pull/456

This change makes the state consistent between user and system crontabs
before processing options:  blanks have been consumed and the next
get_char() returns '-' or the start of the command.

Details:

On system crontabs, multiple blanks are not being consumed after reading the
username. This change adds blank consumption before parsing any -[qn] options.
Without this change, an entry like:

  * * * * * username  -n true  # Two spaces between username and option.

will fail, as the shell will try to execute (' -n true'), while an entry like:

  * * * * * username -n true   # One space between username and option.

works as expected (executes 'true').

For entries without options, this is not an issue, as the leading blanks are
ignored by the shell when executing the command.

For entries with only one blank character between the username and options,
this is also not an issue, as the next get_char() returns '-' and option
processing occurs.

For user crontabs, this is not an issue as the preceding (day of week or
@shortcut) processing consumes any leading whitespace.
Comment 1 commit-hook freebsd_committer 2021-03-04 07:34:40 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=37cd6c20dbcf251e38d6dfb9d3e02022941f6fc7

commit 37cd6c20dbcf251e38d6dfb9d3e02022941f6fc7
Author:     Oleksandr Tymoshenko <gonzo@FreeBSD.org>
AuthorDate: 2021-03-04 07:23:31 +0000
Commit:     Oleksandr Tymoshenko <gonzo@FreeBSD.org>
CommitDate: 2021-03-04 07:23:31 +0000

    cron: consume blanks in system crontabs before options

    On system crontabs, multiple blanks are not being consumed after reading the
    username. This change adds blank consumption before parsing any -[qn] options.
    Without this change, an entry like:

      * * * * * username  -n true  # Two spaces between username and option.

    will fail, as the shell will try to execute (' -n true'), while an entry like:

      * * * * * username -n true   # One space between username and option.

    works as expected (executes 'true').

    For user crontabs, this is not an issue as the preceding (day of week
    or @shortcut) processing consumes any leading whitespace.

    PR:             253699
    Submitted by:   Eric A. Borisch <eborisch@gmail.com>
    MFC after:      1 week

 usr.sbin/cron/lib/entry.c | 3 +++
 1 file changed, 3 insertions(+)
Comment 2 Oleksandr Tymoshenko freebsd_committer freebsd_triage 2021-03-04 07:37:23 UTC
Thanks for the patch. I committed the change and will close the PR once it's MFCed.
Comment 3 eborisch+FreeBSD 2021-04-14 21:57:08 UTC
With 13 out the door, can we get this MFC'ed? Thanks!
Comment 4 commit-hook freebsd_committer 2021-06-05 23:52:13 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=c69de0206511636ebe28ac226dce74f7b204735b

commit c69de0206511636ebe28ac226dce74f7b204735b
Author:     Oleksandr Tymoshenko <gonzo@FreeBSD.org>
AuthorDate: 2021-03-04 07:23:31 +0000
Commit:     Oleksandr Tymoshenko <gonzo@FreeBSD.org>
CommitDate: 2021-06-05 22:49:45 +0000

    cron: consume blanks in system crontabs before options

    On system crontabs, multiple blanks are not being consumed after reading the
    username. This change adds blank consumption before parsing any -[qn] options.
    Without this change, an entry like:

      * * * * * username  -n true  # Two spaces between username and option.

    will fail, as the shell will try to execute (' -n true'), while an entry like:

      * * * * * username -n true   # One space between username and option.

    works as expected (executes 'true').

    For user crontabs, this is not an issue as the preceding (day of week
    or @shortcut) processing consumes any leading whitespace.

    PR:             253699
    Submitted by:   Eric A. Borisch <eborisch@gmail.com>
    MFC after:      1 week

    (cherry picked from commit 37cd6c20dbcf251e38d6dfb9d3e02022941f6fc7)

 usr.sbin/cron/lib/entry.c | 3 +++
 1 file changed, 3 insertions(+)
Comment 5 Oleksandr Tymoshenko freebsd_committer freebsd_triage 2021-06-05 23:58:01 UTC
Merged. Sorry for the delay.