summaryrefslogtreecommitdiffstats
path: root/usr.sbin/newsyslog
diff options
context:
space:
mode:
authorgad <gad@FreeBSD.org>2003-09-09 03:04:50 +0000
committergad <gad@FreeBSD.org>2003-09-09 03:04:50 +0000
commit164bfdbc091928c96e507b36e8d48d94a05f7f51 (patch)
tree86166c786c009619902942bfc0503e8e6e53245d /usr.sbin/newsyslog
parenta19d1825e0d42d6ddb11d92a766ebf6d87e49c7f (diff)
downloadFreeBSD-src-164bfdbc091928c96e507b36e8d48d94a05f7f51.zip
FreeBSD-src-164bfdbc091928c96e507b36e8d48d94a05f7f51.tar.gz
Use strtol() instead of strtoul() in parse8601, so we can detect
negative values. Mainly done to sync this routine with OpenBSD. Obtained from: OpenBSD MFC after: 23 days
Diffstat (limited to 'usr.sbin/newsyslog')
-rw-r--r--usr.sbin/newsyslog/newsyslog.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c
index aaf4159..bf29259 100644
--- a/usr.sbin/newsyslog/newsyslog.c
+++ b/usr.sbin/newsyslog/newsyslog.c
@@ -1737,15 +1737,15 @@ parse8601(char *s)
char *t;
time_t tsecs;
struct tm tm, *tmp;
- u_long ul;
+ long l;
tmp = localtime(&timenow);
tm = *tmp;
tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
- ul = strtoul(s, &t, 10);
- if (*t != '\0' && *t != 'T')
+ l = strtol(s, &t, 10);
+ if (l < 0 || l >= INT_MAX || (*t != '\0' && *t != 'T'))
return (-1);
/*
@@ -1755,17 +1755,17 @@ parse8601(char *s)
*/
switch (t - s) {
case 8:
- tm.tm_year = ((ul / 1000000) - 19) * 100;
- ul = ul % 1000000;
+ tm.tm_year = ((l / 1000000) - 19) * 100;
+ l = l % 1000000;
case 6:
tm.tm_year -= tm.tm_year % 100;
- tm.tm_year += ul / 10000;
- ul = ul % 10000;
+ tm.tm_year += l / 10000;
+ l = l % 10000;
case 4:
- tm.tm_mon = (ul / 100) - 1;
- ul = ul % 100;
+ tm.tm_mon = (l / 100) - 1;
+ l = l % 100;
case 2:
- tm.tm_mday = ul;
+ tm.tm_mday = l;
case 0:
break;
default:
@@ -1779,19 +1779,19 @@ parse8601(char *s)
if (*t != '\0') {
s = ++t;
- ul = strtoul(s, &t, 10);
- if (*t != '\0' && !isspace(*t))
+ l = strtol(s, &t, 10);
+ if (l < 0 || l >= INT_MAX || (*t != '\0' && !isspace(*t)))
return (-1);
switch (t - s) {
case 6:
- tm.tm_sec = ul % 100;
- ul /= 100;
+ tm.tm_sec = l % 100;
+ l /= 100;
case 4:
- tm.tm_min = ul % 100;
- ul /= 100;
+ tm.tm_min = l % 100;
+ l /= 100;
case 2:
- tm.tm_hour = ul;
+ tm.tm_hour = l;
case 0:
break;
default:
OpenPOWER on IntegriCloud