Commit 24919abc authored by Bernhard Link's avatar Bernhard Link

warn against absurd long valid times

Use unsigned long instead of time_t in distribution.h
(to avoid the need to include time.h everywhere) and warn
against absurdly long time spans.
parent 577486fe
......@@ -680,8 +680,8 @@ retvalue config_getword(struct configiterator *iter, char **result_p) {
return config_completeword(iter, c, result_p);
}
retvalue config_gettimespan(struct configiterator *iter, const char *header, time_t *time_p) {
time_t currentnumber, currentsum = 0;
retvalue config_gettimespan(struct configiterator *iter, const char *header, unsigned long *time_p) {
long long currentnumber, currentsum = 0;
bool empty = true;
int c;
......@@ -707,6 +707,11 @@ retvalue config_gettimespan(struct configiterator *iter, const char *header, tim
}
empty = false;
do {
if (currentnumber > 3660) {
configparser_errorlast(iter,
"Absurdly long time span (> 100 years) in %s header.", header);
return RET_ERROR;
}
currentnumber *= 10;
currentnumber += (c - '0');
c = config_nextchar(iter);
......@@ -714,12 +719,32 @@ retvalue config_gettimespan(struct configiterator *iter, const char *header, tim
if (c == ' ' || c == '\t' || c == '\n')
c = config_nextnonspace(iter);
if (c == 'y') {
if (currentnumber > 100) {
configparser_errorlast(iter,
"Absurdly long time span (> 100 years) in %s header.", header);
return RET_ERROR;
}
currentnumber *= 365*24*60*60;
} else if (c == 'm') {
if (currentnumber > 1200) {
configparser_errorlast(iter,
"Absurdly long time span (> 100 years) in %s header.", header);
return RET_ERROR;
}
currentnumber *= 31*24*60*60;
} else if (c == 'd') {
if (currentnumber > 36600) {
configparser_errorlast(iter,
"Absurdly long time span (> 100 years) in %s header.", header);
return RET_ERROR;
}
currentnumber *= 24*60*60;
} else {
if (currentnumber > 36600) {
configparser_errorlast(iter,
"Absurdly long time span (> 100 years) in %s header.", header);
return RET_ERROR;
}
currentnumber *= 24*60*60;
if (c != EOF) {
configparser_errorlast(iter,
......
......@@ -62,7 +62,7 @@ retvalue config_getnumber(struct configiterator *, const char *, long long *, lo
retvalue config_getconstant(struct configiterator *, const struct constant *, int *);
#define config_getenum(iter, type, constants, result) ({int _val;retvalue _r = config_getconstant(iter, type ## _ ## constants, &_val);*(result) = (enum type)_val;_r;})
retvalue config_completeword(struct configiterator *, char, /*@out@*/char **);
retvalue config_gettimespan(struct configiterator *, const char *, /*@out@*/time_t *);
retvalue config_gettimespan(struct configiterator *, const char *, /*@out@*/unsigned long *);
retvalue config_getscript(struct configiterator *, const char *, /*@out@*/char **);
retvalue config_getsignwith(struct configiterator *, const char *, struct strlist *);
void config_overline(struct configiterator *);
......
......@@ -93,7 +93,7 @@ struct distribution {
* files via include */
struct strlist alsoaccept;
/* if != 0, number of seconds to add for Vaild-Until */
time_t validfor;
unsigned long validfor;
/* RET_NOTHING: do not export with EXPORT_CHANGED, EXPORT_NEVER
* RET_OK: export unless EXPORT_NEVER
* RET_ERROR_*: only export with EXPORT_FORCE */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment