]> git.kaiwu.me - haproxy.git/commit
BUG/MINOR: stick-table: reject invalid gpc/gpt array indexes
authorMartin Mirchev <mirchevmartin2203@gmail.com>
Fri, 6 Nov 2026 01:02:11 +0000 (09:02 +0800)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 6 Nov 2026 07:50:19 +0000 (08:50 +0100)
commit88db46dec991008255e77c98dc15035f4ee52538
tree66fdb211ee291eac877a5f8f640c8509fcdda42c
parent64d597032b68c2f43ac1e5b7cb18b8923caf0f89
BUG/MINOR: stick-table: reject invalid gpc/gpt array indexes

The index of the gpc, gpc_rate and gpt arrays is never checked where it
is parsed, so invalid values are silently accepted:

  - the sc-inc-gpc, sc-set-gpt and sc-add-gpc actions parse it with
    strtoul(), which accepts a sign and wraps "-1" to UINT_MAX, and
    which returns 0 for an empty index, so "sc-inc-gpc(,0)" updates
    gpc[0]. Values of 100 and above are accepted as well.

  - the sample fetches and converters taking an index (sc_get_gpc,
    sc_get_gpt, sc_gpc_rate, sc_inc_gpc, sc_clr_gpc, sc1_clr_gpc and the
    src_* and table_* variants) take it as a signed integer without any
    check, so sc_get_gpc(-1,0) or table_gpc(100,t) pass "haproxy -c" and
    never return anything.

  - on the CLI, "data.gpc[-1]" is taken as index 4294967295, so "set
    table" reports "index out of range in this data array" instead of
    rejecting the name as for "data.gpc[q]", and the "show table" and
    "clear table" filters accept it and match no entry, as they do for
    any index beyond the table's array.

Since the index is stored as an unsigned int, values above UINT_MAX are
even truncated: "sc-inc-gpc(4294967296,0)" increments gpc[0] and
sc_get_gpc(4294967296,0) returns gpc[0], and the same happens on the
CLI. There is no memory access issue since stktable_data_ptr_idx()
checks the index against the array size before use, but these errors
should be reported where the index is parsed. The documentation states
that <idx> is an integer between 0 and 99, which is
STKTABLE_MAX_DT_ARRAY_SIZE - 1.

This patch adds stktable_parse_array_idx(), which requires the index to
start with a digit and to be lower than STKTABLE_MAX_DT_ARRAY_SIZE, and
uses it in stktable_get_data_type_idx() and in the three action parsers.
The fetches and converters get a new argument check function which does
the same verification on their first argument. Finally, the CLI table
filters now reject an index beyond the array size of the table, as "set
table" already does. The table is not known when the actions, fetches
and converters are parsed, so they can only be checked against the
maximum array size.

This is the index counterpart of commit 1f1b701fe3 ("BUG/MINOR:
stick-table: reject negative stick counter IDs in sc-* actions").
Configurations using an invalid index are now rejected, but such an
index never worked, or silently used gpc[0]/gpt[0].

This should be backported to all stable versions where the gpc/gpt
arrays exist (2.5 and above). The CLI parts only apply to 3.2 and above
where stktable_get_data_type_idx() was added, and sc-add-gpc() appeared
in 2.8.
src/stick_table.c