From: Hyeonggeun Oh Date: Sat, 28 Nov 2026 10:40:43 +0000 (+0000) Subject: BUG/MINOR: log: preserve NULL bytes of strings with "bin" X-Git-Url: https://git.kaiwu.me/http/%22../$%7BISSUES%7D/static/%7B@url%7D?a=commitdiff_plain;h=1ed3663c43f36d05071a3dbb1f2274feb3fcd68a;p=haproxy.git BUG/MINOR: log: preserve NULL bytes of strings with "bin" This fixes issue #3489: when forwarding a received TLV with set-proxy-v2-tlv-fmt() "%[fc_pp_tlv()]", the value is cut at the first NULL byte. fc_pp_tlv returns a string, and _lf_text_len() copies strings with strlcpy2(). The "bin" option did not help since it only applied to binary samples. With the patch, when "bin" is set, strings are copied according to thier length, like binary samples. Without "bin", nothing changes. CBOR encoding is untouched. Note: lf_text()/lf_rawtext() used to pass the remaining buffer size as the length of NUL-terminated fields (relying on strlcpy2() to stop). With "bin" they now pass strnlen(src, size), otherwise "%{+bin}o%f" would read past the end of the string (caught with ASAN on an earlier version of this patch). Tested on master c2852d5b7: new reg-test plus reg-tests/log pass, full reg-tests 299 pass / 0 fail (no SSL/Lua build). An earlier version was also tested with ASAN + SSL/Lua (394 pass / 0 fail). One open question: since TLV values are binary by nature, should set-proxy-v2-tlv-fmt enable "bin" by default? I did not do it because it changes the behavior of existing configurations, but I can send a follow-up patch if you think it makes sense. It may be backported to 3.0, where "bin" was introduced. Signed-off-by: Hyeonggeun Oh --- diff --git a/doc/configuration.txt b/doc/configuration.txt index cc84f9ae5..2e5de22d6 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -20876,6 +20876,13 @@ set-proxy-v2-tlv-fmt() In this case, we fetch the TLV with the type 0x20 as a string and set as the value of a newly created TLV that also has the type 0x20. + Note that is a log-format string: by default, a value is emitted as text + and stops at the first NULL byte. To forward a binary TLV value which may + contain NULL bytes, enable the "bin" option globally for the format: + + server srv1 192.168.1.1:80 send-proxy-v2 \ + set-proxy-v2-tlv-fmt(0xE1) "%{+bin}o%[fc_pp_tlv(0xE1)]" + proxy-v2-options