From: Christopher Faulet Date: Fri, 11 Dec 2020 08:23:07 +0000 (+0100) Subject: BUG/MINOR: tools: make parse_time_err() more strict on the timer validity X-Git-Tag: v2.4-dev3~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c20ad0d8dbd1bb5707bbfe23632415c3062e046c;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/src/tools.c b/src/tools.c index 1f6c2b99dc..590a101e89 100644 --- a/src/tools.c +++ b/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; }