Avoid infinite loops when the day of the week in cron is out of limits

Former-commit-id: 6c0a87a29818219364fb9c08c44b48cb79dd74a8
This commit is contained in:
fermin831 2019-04-05 12:32:43 +02:00
parent e50fb4c585
commit 873525726e
3 changed files with 16 additions and 1 deletions

View File

@ -2102,6 +2102,12 @@ sub cron_next_execution {
# Get day of the week and month from cron config
my ($wday) = (split (/\s/, $cron))[4];
# Check the wday values to avoid infinite loop
my ($wday_down, $wday_up) = cron_get_interval($wday);
if ($wday_down ne "*" && ($wday_down > 6 || (defined($wday_up) && $wday_up > 6))) {
log_message('setup', "Invalid cron configuration $cron. Day of the week is out of limits.");
$wday = "*";
}
# Get current time and day of the week
my $cur_time = time();
@ -2110,7 +2116,6 @@ sub cron_next_execution {
my $nex_time = cron_next_execution_date ($cron, $cur_time, $interval);
# Check the day
print localtime($nex_time)->strftime('%c') . " - OUTSIDE\n";
while (!cron_check_interval($wday, (localtime ($nex_time))[6])) {
# If it does not acomplish the day of the week, go to the next day.
$nex_time += 86400;

View File

@ -83,6 +83,11 @@ function cron_next_execution($cron, $module_interval, $module_id)
$cur_time = ($last_execution !== false) ? $last_execution : time();
$nex_time = cron_next_execution_date($cron, $cur_time, $module_interval);
$nex_wday = (int) date('w', $nex_time);
// Check the wday values to avoid infinite loop.
$wday_int = cron_get_interval($wday);
if ($wday_int['down'] !== '*' && ($wday_int['down'] > 6 || ($wday_int['up'] !== false && $wday_int['up'] > 6))) {
$wday = '*';
}
// Check day of the way.
while (!cron_check_interval($nex_wday, $wday)) {

View File

@ -1360,6 +1360,11 @@ sub cron_next_execution {
# Get day of the week and month from cron config
my ($wday) = (split (/\s/, $cron))[4];
# Check the wday values to avoid infinite loop
my ($wday_down, $wday_up) = cron_get_interval($wday);
if ($wday_down ne "*" && ($wday_down > 6 || (defined($wday_up) && $wday_up > 6))) {
$wday = "*";
}
# Get current time and day of the week
my $cur_time = time();