1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
From: Georges Khaznadar <georgesk@debian.org>
Date: Sun, 15 Oct 2023 18:04:15 +0200
Subject: step-size out of bound handling
This work comes from Alexander Schwinn <alexander.schwinn@gmx.de>, it is about
checking steps in crontabs, to prevent insane divisions, like dividing
one hour in more than 60 steps for example
---
entry.c | 32 +++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)
diff --git a/entry.c b/entry.c
index c3602ae..8c614b1 100644
--- a/entry.c
+++ b/entry.c
@@ -430,20 +430,20 @@ get_range(bits, low, high, names, ch, file)
*/
register int i;
- auto int num1, num2, num3;
+ auto int low_, high_, step;
Debug(DPARS|DEXT, ("get_range()...entering, exit won't show\n"))
if (ch == '*') {
/* '*' means "first-last" but can still be modified by /step
*/
- num1 = low;
- num2 = high;
+ low_ = low;
+ high_ = high;
ch = get_char(file);
if (ch == EOF)
return EOF;
} else {
- if (EOF == (ch = get_number(&num1, low, names, ch, file)))
+ if (EOF == (ch = get_number(&low_, low, names, ch, file)))
return EOF;
if (ch != '-') {
@@ -456,7 +456,7 @@ get_range(bits, low, high, names, ch, file)
if (ch == '/')
return EOF;
- if (EOF == set_element(bits, low, high, num1))
+ if (EOF == set_element(bits, low, high, low_))
return EOF;
return ch;
} else {
@@ -468,7 +468,7 @@ get_range(bits, low, high, names, ch, file)
/* get the number following the dash
*/
- ch = get_number(&num2, low, names, ch, file);
+ ch = get_number(&high_, low, names, ch, file);
if (ch == EOF)
return EOF;
}
@@ -488,13 +488,13 @@ get_range(bits, low, high, names, ch, file)
* element id, it's a step size. 'low' is
* sent as a 0 since there is no offset either.
*/
- ch = get_number(&num3, 0, PPC_NULL, ch, file);
- if (ch == EOF || num3 <= 0)
+ ch = get_number(&step, 0, PPC_NULL, ch, file);
+ if (ch == EOF || step <= 0)
return EOF;
} else {
/* no step. default==1.
*/
- num3 = 1;
+ step = 1;
}
/* Explicitly check for sane values. Certain combinations of ranges and
@@ -505,15 +505,21 @@ get_range(bits, low, high, names, ch, file)
* Code adapted from set_elements() where this error was probably intended
* to be catched.
*/
- if (num1 < low || num1 > high || num2 < low || num2 > high)
+ if (low_ < low || low_ > high || high_ < low || high_ > high)
return EOF;
- /* range. set all elements from num1 to num2, stepping
- * by num3. (the step is a downward-compatible extension
+ /* Make sure the step size makes any sense */
+ if (step > 1 && step > (high_ - low_)) {
+ int max = high_ - low_ > 0 ? high_ - low_ : 1;
+ fprintf(stderr, "Warning: Step size %i higher than possible maximum of %i\n", step, max);
+ }
+
+ /* range. set all elements from low_ to high_, stepping
+ * by step. (the step is a downward-compatible extension
* proposed conceptually by bob@acornrc, syntactically
* designed then implmented by paul vixie).
*/
- for (i = num1; i <= num2; i += num3)
+ for (i = low_; i <= high_; i += step)
if (EOF == set_element(bits, low, high, i))
return EOF;
|