mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2024-12-18 09:24:31 +00:00
BUG/MINOR: tools: make parse_time_err() more strict on the timer validity
First, an error is now reported if the first character is not a digit. Thus, "timeout client s" triggers an error now. Then 'u' is also rejected now. 'us' is valid and should be used set the timer in microseconds. However 'u' alone is not a valid unit. It was just ignored before (default to milliseconds). Now, it is an error. Finally, a warning is reported if the end of the text is not reached after the timer parsing. This warning will probably be switched to an error in a futur version. This patch must be backported to all stable versions.
This commit is contained in:
parent
cad5f5e1ed
commit
c20ad0d8db
14
src/tools.c
14
src/tools.c
@ -2216,6 +2216,10 @@ const char *parse_time_err(const char *text, unsigned *ret, unsigned unit_flags)
|
||||
unsigned long long imult, idiv;
|
||||
unsigned long long omult, odiv;
|
||||
unsigned long long value, result;
|
||||
const char *str = text;
|
||||
|
||||
if (!isdigit((unsigned char)*text))
|
||||
return text;
|
||||
|
||||
omult = odiv = 1;
|
||||
|
||||
@ -2246,7 +2250,7 @@ const char *parse_time_err(const char *text, unsigned *ret, unsigned unit_flags)
|
||||
switch (*text) {
|
||||
case '\0': /* no unit = default unit */
|
||||
imult = omult = idiv = odiv = 1;
|
||||
break;
|
||||
goto end;
|
||||
case 's': /* second = unscaled unit */
|
||||
break;
|
||||
case 'u': /* microsecond : "us" */
|
||||
@ -2254,7 +2258,7 @@ const char *parse_time_err(const char *text, unsigned *ret, unsigned unit_flags)
|
||||
idiv = 1000000;
|
||||
text++;
|
||||
}
|
||||
break;
|
||||
return text;
|
||||
case 'm': /* millisecond : "ms" or minute: "m" */
|
||||
if (text[1] == 's') {
|
||||
idiv = 1000;
|
||||
@ -2272,7 +2276,13 @@ const char *parse_time_err(const char *text, unsigned *ret, unsigned unit_flags)
|
||||
return text;
|
||||
break;
|
||||
}
|
||||
if (*(++text) != '\0') {
|
||||
ha_warning("unexpected character '%c' after the timer value '%s', only "
|
||||
"(us=microseconds,ms=milliseconds,s=seconds,m=minutes,h=hours,d=days) are supported."
|
||||
" This will be reported as an error in next versions.\n", *text, str);
|
||||
}
|
||||
|
||||
end:
|
||||
if (omult % idiv == 0) { omult /= idiv; idiv = 1; }
|
||||
if (idiv % omult == 0) { idiv /= omult; omult = 1; }
|
||||
if (imult % odiv == 0) { imult /= odiv; odiv = 1; }
|
||||
|
Loading…
Reference in New Issue
Block a user