]> git.kaiwu.me - haproxy.git/commit
BUG/MINOR: pattern: don't rely on the trash size to read pattern files
authorDongwon Jang <contact@dongwonjang.com>
Tue, 17 Nov 2026 01:47:22 +0000 (10:47 +0900)
committerWilly Tarreau <w@1wt.eu>
Wed, 25 Nov 2026 10:33:05 +0000 (11:33 +0100)
commitfc0068e70cb66bb4d3078a1e724f078c314476c7
tree759c2eb7efe4cae25a7b6f24a37b2b583c1c2b72
parent44556c0c0aabb9190f4cbf46863148a3d98f77eb
BUG/MINOR: pattern: don't rely on the trash size to read pattern files

Since commit 3ef263987 ("MEDIUM: chunks: Realloc trash buffers only after
the config is parsed and checked") in 1.8, the trash keeps its early
default size (BUFSIZE) until init_trash_buffers() is called after
check_config_validity(). Pattern files (maps, ACL "-f" files and
set-vars-from-map files) are loaded before that point, and their lines are
read with fgets() into the trash. As a result, a line longer than BUFSIZE-1
(16383 by default) is silently split regardless of tune.bufsize: the first
part is loaded with a truncated value and the remainder is loaded as one or
more extra entries, without any warning. For ACLs, this also means that the
16383-char prefix of a long pattern matches while the full pattern does
not. The only workarounds are to shorten such lines or to set the entries
again from the CLI after each reload.

Let's read pattern file lines with read_line_to_mem() instead, which uses
a dedicated heap buffer that grows as needed. Resizing the trash earlier
was not an option since ACL files are loaded while parsing. Values remain
bounded at runtime by tune.bufsize since pattern_exec_match() copies the
matched sample into a trash chunk, which is consistent with what can be
set from the CLI.

A reg-test was added which checks that a map file and an ACL file holding
a single 20000-char line are each loaded as a single entry, and that the
map value is returned in full.

This fixes GitHub issue #3537.

This should be backported to all stable versions, along with the previous
commit "MINOR: tools: add read_line_to_mem() to read a line into a growing
buffer" which it depends on. Before 3.0, the two pat_ref_read_from_file*()
functions take the file name as an argument, which only changes the patch
context.
reg-tests/http-rules/map_acl_long_lines.vtc [new file with mode: 0644]
src/pattern.c