From: Martin Mirchev Date: Wed, 18 Nov 2026 12:36:59 +0000 (+0800) Subject: BUG/MINOR: mux-h2: reject non-numeric values in the tune.h2 keywords X-Git-Url: https://git.kaiwu.me/http/%7Bsubstring-before(@doc,%20'.xml')%7D.html?a=commitdiff_plain;h=8475b372c;p=haproxy.git BUG/MINOR: mux-h2: reject non-numeric values in the tune.h2 keywords The tune.h2 numeric keywords are parsed with atoi(), so trailing garbage and non-numeric values are silently accepted: "tune.h2.max-frame-size 16384x" sets 16384, "tune.h2.fe.max-total-streams x" and "tune.h2.fe.glitches-threshold x" set 0, which means "unlimited" for both, "tune.h2.header-table-size 8192k" sets 8192 and a missing glitches value is taken as 0. The same applies to initial-window-size, max-concurrent-streams (including its "rq-load" and "min" values) and the max-{frames,rst}-at-once keywords, where a negative value is also silently turned into a huge unsigned limit. Parse these values with strtol() and reject empty values, trailing characters and values that do not fit in an int, keeping the existing range checks and error messages. max-{frames,rst}-at-once now also reject negative values. This should be backported to all stable versions. --- diff --git a/src/mux_h2.c b/src/mux_h2.c index 3ae71a065..56c03a1f9 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -9081,6 +9081,23 @@ static int h2_takeover(struct connection *conn, int orig_tid, int release) /* functions below are dedicated to the config parsers */ /*******************************************************/ +/* Parses as a decimal integer into <*val>. Returns 0 on success, or -1 + * if is empty, contains anything but an optional sign and digits, or + * does not fit in an int. + */ +static int h2_parse_int(const char *arg, int *val) +{ + char *end; + long v; + + errno = 0; + v = strtol(arg, &end, 10); + if (!*arg || *end || errno || v < INT_MIN || v > INT_MAX) + return -1; + *val = v; + return 0; +} + /* config parser for global "tune.h2.{fe,be}.glitches-threshold" */ static int h2_parse_glitches_threshold(char **args, int section_type, struct proxy *curpx, const struct proxy *defpx, const char *file, int line, @@ -9094,8 +9111,7 @@ static int h2_parse_glitches_threshold(char **args, int section_type, struct pro /* backend/frontend */ vptr = (args[0][8] == 'b') ? &h2_be_glitches_threshold : &h2_fe_glitches_threshold; - *vptr = atoi(args[1]); - if (*vptr < 0) { + if (h2_parse_int(args[1], vptr) || *vptr < 0) { memprintf(err, "'%s' expects a positive numeric value.", args[0]); return -1; } @@ -9110,8 +9126,8 @@ static int h2_parse_header_table_size(char **args, int section_type, struct prox if (too_many_args(1, args, err, NULL)) return -1; - h2_settings_header_table_size = atoi(args[1]); - if (h2_settings_header_table_size < 4096 || h2_settings_header_table_size > 65536) { + if (h2_parse_int(args[1], &h2_settings_header_table_size) || + h2_settings_header_table_size < 4096 || h2_settings_header_table_size > 65536) { memprintf(err, "'%s' expects a numeric value between 4096 and 65536.", args[0]); return -1; } @@ -9133,8 +9149,7 @@ static int h2_parse_initial_window_size(char **args, int section_type, struct pr (args[0][8] == 'f') ? &h2_fe_settings_initial_window_size : &h2_settings_initial_window_size; - *vptr = atoi(args[1]); - if (*vptr < 0) { + if (h2_parse_int(args[1], vptr) || *vptr < 0) { memprintf(err, "'%s' expects a positive numeric value.", args[0]); return -1; } @@ -9183,8 +9198,7 @@ static int h2_parse_max_concurrent_streams(char **args, int section_type, struct if (args[0][8] != 'f' && too_many_args(1, args, err, NULL)) return -1; - *vptr = atoi(args[1]); - if ((int)*vptr < 0) { + if (h2_parse_int(args[1], (int *)vptr) || (int)*vptr < 0) { memprintf(err, "'%s' expects a positive numeric value.", args[0]); return -1; } @@ -9199,13 +9213,13 @@ static int h2_parse_max_concurrent_streams(char **args, int section_type, struct h2_fe_max_rq_load = ~0; else if (strcmp(args[arg + 1], "auto") == 0) h2_fe_max_rq_load = 0; - else if (!*args[arg + 1] || (h2_fe_max_rq_load = atoi(args[arg + 1])) <= 0) { + else if (h2_parse_int(args[arg + 1], (int *)&h2_fe_max_rq_load) || (int)h2_fe_max_rq_load <= 0) { memprintf(err, "'%s' expects a strictly positive run-queue length, or 'auto' or 'ignore'.", args[0]); return -1; } } else if (strcmp(args[arg], "min") == 0) { - if (!*args[arg + 1] || (h2_fe_min_concurrent_streams = atoi(args[arg + 1])) <= 0) { + if (h2_parse_int(args[arg + 1], (int *)&h2_fe_min_concurrent_streams) || (int)h2_fe_min_concurrent_streams <= 0) { memprintf(err, "'%s' expects a strictly positive minimum number of streams'.", args[0]); return -1; } @@ -9238,8 +9252,7 @@ static int h2_parse_max_total_streams(char **args, int section_type, struct prox /* frontend only for now */ vptr = &h2_fe_max_total_streams; - *vptr = atoi(args[1]); - if ((int)*vptr < 0) { + if (h2_parse_int(args[1], (int *)vptr) || (int)*vptr < 0) { memprintf(err, "'%s' expects a positive numeric value.", args[0]); return -1; } @@ -9266,7 +9279,10 @@ static int h2_parse_max_frames_at_once(char **args, int section_type, struct pro if (too_many_args(1, args, err, NULL)) return -1; - *vptr = atoi(args[1]); + if (h2_parse_int(args[1], (int *)vptr) || (int)*vptr < 0) { + memprintf(err, "'%s' expects a positive numeric value.", args[0]); + return -1; + } return 0; } @@ -9278,8 +9294,8 @@ static int h2_parse_max_frame_size(char **args, int section_type, struct proxy * if (too_many_args(1, args, err, NULL)) return -1; - h2_settings_max_frame_size = atoi(args[1]); - if (h2_settings_max_frame_size < 16384 || h2_settings_max_frame_size > 16777215) { + if (h2_parse_int(args[1], &h2_settings_max_frame_size) || + h2_settings_max_frame_size < 16384 || h2_settings_max_frame_size > 16777215) { memprintf(err, "'%s' expects a numeric value between 16384 and 16777215.", args[0]); return -1; }