Skip to content

Commit

Permalink
fix(cron): fix the range limits for minutes, hours, and weeks
Browse files Browse the repository at this point in the history
Minutes: 0 to 59
Hours: 0 to 23
Weeks: 0 to 7, where both 0 and 7 represent Sunday
  • Loading branch information
Water-Melon committed Jan 14, 2025
1 parent 6af2d2c commit 89c850a
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/mln_cron.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ MLN_FUNC(static, long, mln_cron_parse_minute, (mln_string_t *smin, long min), (s
if (p == head || p > head + 2) return -1;
*p = 0;
tmp = atol((char *)head);
if (tmp < 1 || tmp >= 60) {
return -1;
}
if (tmp < 1 || tmp >= 60) return -1;
if (tmp < min) tmp += 60;
if (!save) {
save = min == tmp? min + period: tmp;
Expand All @@ -110,7 +108,7 @@ MLN_FUNC(static, long, mln_cron_parse_minute, (mln_string_t *smin, long min), (s
if (p > head) {
if (p > head + 2) return -1;
tmp = atol((char *)head);
if (tmp < 1 || tmp >= 60) return -1;
if (tmp < 0 || tmp >= 60) return -1;
if (tmp < min) tmp += 60;
if (!save) {
save = min == tmp? min + period: tmp;
Expand Down Expand Up @@ -178,7 +176,7 @@ MLN_FUNC(static, long, mln_cron_parse_hour, \
if (p > head) {
if (p > head + 2) return -1;
tmp = atol((char *)head);
if (tmp < 1 || tmp >= 24) return -1;
if (tmp < 0 || tmp >= 24) return -1;
if (tmp < hour) tmp += 24;
if (!save) {
save = hour==tmp && !greater? hour + period: tmp;
Expand Down Expand Up @@ -394,6 +392,7 @@ MLN_FUNC(static, long, mln_cron_parse_week, \
if (p > head) {
if (p > head + 1) return -1;
tmp = atol((char *)head);
if (tmp == 7) tmp = 0;
if (tmp < 0 || tmp >= 7) return -1;
if (tmp < week) tmp += 7;
if (!save) {
Expand Down

0 comments on commit 89c850a

Please sign in to comment.