]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: config: round up global.tune.bufsize to the next multiple of 2 void*
authorWilly Tarreau <w@1wt.eu>
Wed, 12 Dec 2018 05:19:42 +0000 (06:19 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 12 Dec 2018 05:19:42 +0000 (06:19 +0100)
Since HTX casts the buffer to a struct and stores relative pointers at the
end, it is mandatory that its end is properly aligned. This patch enforces
a buffer size rounding up to the next multiple of two void*, thus 8 on
32-bit and 16 on 64-bit, to match what malloc() already does on the beginning
of the buffer. In pratice it will never be really noticeable since default
sizes already are such multiples.

doc/configuration.txt
src/cfgparse-global.c
src/haproxy.c

index 400ec6402c8801dc6c7b44832c25ded15f2b1c9c..d1322233132347cc5b107ec8b7a4e83e17d0e682 100644 (file)
@@ -1532,7 +1532,9 @@ tune.bufsize <number>
   addition, use of HTTP/2 mandates that this value must be 16384 or more. If an
   HTTP request is larger than (tune.bufsize - tune.maxrewrite), haproxy will
   return HTTP 400 (Bad Request) error. Similarly if an HTTP response is larger
-  than this size, haproxy will return HTTP 502 (Bad Gateway).
+  than this size, haproxy will return HTTP 502 (Bad Gateway). Note that the
+  value set using this parameter will automatically be rounded up to the next
+  multiple of 8 on 32-bit machines and 16 on 64-bit machines.
 
 tune.chksize <number>
   Sets the check buffer size to this size (in bytes). Higher values may help
index 4303ef9875a68b5aa735273be044521bb703e6e9..5a92d9b313fc57ca7bc7ffee7fc3e9819363934c 100644 (file)
@@ -206,6 +206,8 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
                        goto out;
                }
                global.tune.bufsize = atol(args[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) {
                        ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]);
                        err_code |= ERR_ALERT | ERR_FATAL;
index 6c96794e23c3b9600b5dc8bd810fc517e39df6f7..4af888073afeb586517d0a085e08589e6e7f67dd 100644 (file)
@@ -149,9 +149,9 @@ struct global global = {
                 }
        },
        .tune = {
-               .bufsize = BUFSIZE,
+               .bufsize = (BUFSIZE + 2*sizeof(void *) - 1) & -(2*sizeof(void *)),
                .maxrewrite = -1,
-               .chksize = BUFSIZE,
+               .chksize = (BUFSIZE + 2*sizeof(void *) - 1) & -(2*sizeof(void *)),
                .reserved_bufs = RESERVED_BUFS,
                .pattern_cache = DEFAULT_PAT_LRU_SIZE,
 #ifdef USE_OPENSSL