]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: config: insufficient syntax check of the global "maxconn" value
authorThierry Fournier <tfournier@arpalert.org>
Sat, 1 Oct 2022 08:06:59 +0000 (10:06 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 3 Oct 2022 12:30:08 +0000 (14:30 +0200)
The maxconn value is decoded using atol(), so values like "3k" are
rightly converter as interger 3, while the user wants 3000.

This patch fixes this behavior by reporting a parsing error.

This patch could be backported on all maintained version, but it
could break some configuration. The bug is really minor, I recommend
to not backport, or backport a patch which only throws a warning in
place of a fatal error.

src/cfgparse-global.c

index cd96fb676d62d26e5c66b3b68079bbd0e9005a93..62de1013a871687baac2b44389963ca8fc70bce0 100644 (file)
@@ -592,6 +592,8 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
                goto out;
        }
        else if (strcmp(args[0], "maxconn") == 0) {
+               char *stop;
+
                if (alertif_too_many_args(1, file, linenum, args, &err_code))
                        goto out;
                if (global.maxconn != 0) {
@@ -604,7 +606,12 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
                        err_code |= ERR_ALERT | ERR_FATAL;
                        goto out;
                }
-               global.maxconn = atol(args[1]);
+               global.maxconn = strtol(args[1], &stop, 10);
+               if (*stop != '\0') {
+                       ha_alert("parsing [%s:%d] : cannot parse '%s' value '%s', an integer is expected.\n", file, linenum, args[0], args[1]);
+                       err_code |= ERR_ALERT | ERR_FATAL;
+                       goto out;
+               }
 #ifdef SYSTEM_MAXCONN
                if (global.maxconn > SYSTEM_MAXCONN && cfg_maxconn <= SYSTEM_MAXCONN) {
                        ha_alert("parsing [%s:%d] : maxconn value %d too high for this system.\nLimiting to %d. Please use '-n' to force the value.\n", file, linenum, global.maxconn, SYSTEM_MAXCONN);