]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cfgparse: parse tune.recv_enough as a size
authorWilly Tarreau <w@1wt.eu>
Mon, 18 Nov 2024 18:01:28 +0000 (19:01 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 18 Nov 2024 18:01:28 +0000 (19:01 +0100)
Till now this value was parsed as raw integer using atol() and would
silently ignore any trailing suffix, causing unexpected behaviors when
set, e.g. to "512k". 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
since it's sometimes compared to an int, we limit its range to
0..INT_MAX.

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

index 09762df884c462fb48c122dfa673479a008a8ee0..29fe89af9e28558962fb9a28dda77f53a83b8ccb 100644 (file)
@@ -4111,7 +4111,7 @@ tune.rcvbuf.server <size>
   order to save kernel memory by preventing it from buffering too large amounts
   of received data. Lower values will significantly increase CPU usage though.
 
-tune.recv_enough <number>
+tune.recv_enough <size>
   HAProxy uses some hints to detect that a short read indicates the end of the
   socket buffers. One of them is that a read returns more than <recv_enough>
   bytes, which defaults to 10136 (7 segments of 1448 each). This default value
index 0d683158671ce846bfb506bd0cf1e7ec0b47eb4c..a013b96e606a223fb987a810b7400cc2c9005227 100644 (file)
@@ -164,7 +164,7 @@ struct global {
                int maxaccept;     /* max number of consecutive accept() */
                int options;       /* various tuning options */
                int runqueue_depth;/* max number of tasks to run at once */
-               int recv_enough;   /* how many input bytes at once are "enough" */
+               uint recv_enough;  /* how many input bytes at once are "enough" */
                int 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 */
index 13842bb1994ae50bf8aaa68f6f1b97d2b3f68395..61c5a20201fec7ab9a85aaf6a6c5f3624bfe5b17 100644 (file)
@@ -1179,7 +1179,14 @@ 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.recv_enough = atol(args[1]);
+               res = parse_size_err(args[1], &global.tune.recv_enough);
+               if (res != NULL)
+                       goto size_err;
+
+               if (global.tune.recv_enough > INT_MAX) {
+                       memprintf(err, "'%s' expects a size in bytes from 0 to %d.", args[0], INT_MAX);
+                       return -1;
+               }
 
                return 0;
        }