]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: tools: make parse_time_err() more strict on the timer validity
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 11 Dec 2020 08:23:07 +0000 (09:23 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 11 Dec 2020 11:01:04 +0000 (12:01 +0100)
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.

src/tools.c

index 1f6c2b99dc2a15b1d60656a0e3e18dee118ada09..590a101e89758012bc9010f366ab70c3ea2312ea 100644 (file)
@@ -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; }