]> git.kaiwu.me - haproxy.git/commit
BUG/MINOR: server: fix off-by-one error when parsing and copying source port range
authorFrederic Lecaille <flecaille@haproxy.com>
Wed, 12 Aug 2026 17:06:07 +0000 (19:06 +0200)
committerFrederic Lecaille <flecaille@haproxy.com>
Wed, 12 Aug 2026 17:06:07 +0000 (19:06 +0200)
commit59690ae14281d155311cb5c373ddefb37923968d
treea7ff31a5d94cce0716384b79ad51ffe734061163
parent0378631eeb57a308333d1f29a8635a78ee9ca753
BUG/MINOR: server: fix off-by-one error when parsing and copying source port range

When allocating a source port range, port_range_alloc_range() allocates
a ring structure of size n + 1 to accommodate a sentinel slot for the
lock-free ring buffer.

However, both srv_parse_source() and srv_conn_src_sport_range_cpy()
were incorrectly using range->size directly, filling and copying the
sentinel slot as if it were a valid port. This ->size port_range struct
field should never be used.

This off-by-one error caused an extra port to be populated. When copying a
configuration (e.g. via default-server or server-template), this extra
slot became allocatable, allowing connections to bind beyond the configured
port range (e.g. binding port 5002 when 5000-5001 was set). Furthermore, if
the range reached port 65535, the extra port wrapped to 0, producing
CO_ER_PORT_RANGE connection failures.

Fix this by introducing port_range_count() to cleanly return the number of
usable ports (range->size - 1), and use it in both srv_parse_source()
and srv_conn_src_sport_range_cpy().

Many thanks to Red Hat and AISLE Research for reporting this.

Must be backported as far as 2.6.
include/haproxy/port_range.h
src/server.c