]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cfgparse: parse tune.bufsize as a size
authorWilly Tarreau <w@1wt.eu>
Mon, 18 Nov 2024 18:04:57 +0000 (19:04 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 18 Nov 2024 18:06:25 +0000 (19:06 +0100)
Till now this value was parsed as raw integer using atol() and would
silently ignore any trailing suffix, preventing from starting when set
e.g. to "64k". Let's make use of parse_size_err() on it so that units are
supported. This requires to turn it to uint as well, and to explicitly
limit its range to INT_MAX - 2*sizeof(void*), which was previously
partially handled as part of the sign check.

doc/configuration.txt
include/haproxy/global-t.h
src/cfgparse-global.c

index 29fe89af9e28558962fb9a28dda77f53a83b8ccb..793716a5a610e7a3002ba5d238880dab0193b5d4 100644 (file)
@@ -3320,7 +3320,7 @@ tune.buffers.reserve <number>
   a user would want to change this value, unless a core developer suggests to
   change it for a very specific reason.
 
-tune.bufsize <number>
+tune.bufsize <size>
   Sets the buffer size to this size (in bytes). Lower values allow more
   streams to coexist in the same amount of RAM, and higher values allow some
   applications with very large cookies to work. The default value is 16384 and
index a013b96e606a223fb987a810b7400cc2c9005227..0a176a65f50ea55095cfa10d6a63c268a44db778 100644 (file)
@@ -165,7 +165,7 @@ struct global {
                int options;       /* various tuning options */
                int runqueue_depth;/* max number of tasks to run at once */
                uint recv_enough;  /* how many input bytes at once are "enough" */
-               int bufsize;       /* buffer size in bytes, defaults to BUFSIZE */
+               uint bufsize;      /* buffer size in bytes, defaults to BUFSIZE */
                int bufsize_small; /* small buffer size in bytes */
                int maxrewrite;    /* buffer max rewrite size in bytes, defaults to MAXREWRITE */
                int reserved_bufs; /* how many buffers can only be allocated for response */
index 61c5a20201fec7ab9a85aaf6a6c5f3624bfe5b17..b8369c821ea05c02a918ff4675cd3babd180d1b8 100644 (file)
@@ -1195,7 +1195,16 @@ static int cfg_parse_global_tune_opts(char **args, int section_type,
                        memprintf(err, "'%s' expects an integer argument", args[0]);
                        return -1;
                }
-               global.tune.bufsize = atol(args[1]);
+               res = parse_size_err(args[1], &global.tune.bufsize);
+               if (res != NULL)
+                       goto size_err;
+
+               if (global.tune.bufsize > INT_MAX - (int)(2 * sizeof(void *))) {
+                       memprintf(err, "'%s' expects a size in bytes from 0 to %d.",
+                                 args[0], INT_MAX - (int)(2 * sizeof(void *)));
+                       return -1;
+               }
+
                /* round it up to support a two-pointer alignment at the end */
                global.tune.bufsize = (global.tune.bufsize + 2 * sizeof(void *) - 1) & -(2 * sizeof(void *));
                if (global.tune.bufsize <= 0) {