Hello HAProxy team,
This fixes issue #3489: when forwarding a received TLV with
set-proxy-v2-tlv-fmt(<id>) "%[fc_pp_tlv(<id>)]", 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.
Regards,
Hyeonggeun.