From afce06c3d33afd5bfa7b6a5ead427cd304131b07 Mon Sep 17 00:00:00 2001
From: Jan-Philipp Litza <janphilipp@litza.de>
Date: Wed, 27 Aug 2014 10:11:17 +0200
Subject: [PATCH] gluon-cron: Fix endless loop parsing invalid lines

Using the line
```
* * * * echo "foobar"
```
(notice the missing fifth time field) in a crontab causes gluon-cron
to enter an endless loop while parsing it, thus it won't even execute
the other, valid crontabs.

This is caused by the loop in [line 138] where `begin - min`
substracts the unsigned `min` from the signed `begin`. If now `begin`
is invalid, `strict_atoi` returns -1 and the loop starts at
`(-1)-1=MAX_INT` and runs while `i <= MAX_INT` which is always true.

The real culprit lies in [line 134] where exactly this case
`begin < min` is checked - but because of the signedness, this check doesn't
work as expected either.

The easiest solution is to make `min` a signed integer instead of an unsigned
one, as we do not require it to be very large and only pass the constants 0 or
1 to it.

To avoid other similar problems, this patch makes the input variable `n` a
signed integer as well.
---
 package/gluon-cron/src/gluon-crond.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/package/gluon-cron/src/gluon-crond.c b/package/gluon-cron/src/gluon-crond.c
index 9ca9d891b..11a87c42c 100644
--- a/package/gluon-cron/src/gluon-crond.c
+++ b/package/gluon-cron/src/gluon-crond.c
@@ -94,7 +94,7 @@ static uint64_t parse_strings(const char *input, const char *const *strings, siz
 	return 0;
 }
 
-static uint64_t parse_times(char *input, unsigned min, unsigned n) {
+static uint64_t parse_times(char *input, int min, int n) {
 	uint64_t ret = 0;
 	int step = 1;
 
-- 
GitLab