MINOR: cfgparse: parse tune.bufsize as a size

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.
This commit is contained in:
Willy Tarreau 2024-11-18 19:04:57 +01:00
parent 2f0c6ff3a5
commit a344d37fad
3 changed files with 12 additions and 3 deletions

View File

@ -3320,7 +3320,7 @@ tune.buffers.reserve <number>
a user would want to change this value, unless a core developer suggests to a user would want to change this value, unless a core developer suggests to
change it for a very specific reason. 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 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 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 applications with very large cookies to work. The default value is 16384 and

View File

@ -165,7 +165,7 @@ struct global {
int options; /* various tuning options */ int options; /* various tuning options */
int runqueue_depth;/* max number of tasks to run at once */ int runqueue_depth;/* max number of tasks to run at once */
uint 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 */ uint bufsize; /* buffer size in bytes, defaults to BUFSIZE */
int bufsize_small; /* small buffer size in bytes */ int bufsize_small; /* small buffer size in bytes */
int maxrewrite; /* buffer max rewrite size in bytes, defaults to MAXREWRITE */ int maxrewrite; /* buffer max rewrite size in bytes, defaults to MAXREWRITE */
int reserved_bufs; /* how many buffers can only be allocated for response */ int reserved_bufs; /* how many buffers can only be allocated for response */

View 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]); memprintf(err, "'%s' expects an integer argument", args[0]);
return -1; 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 */ /* 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 *)); global.tune.bufsize = (global.tune.bufsize + 2 * sizeof(void *) - 1) & -(2 * sizeof(void *));
if (global.tune.bufsize <= 0) { if (global.tune.bufsize <= 0) {