MINOR: resolvers: fix the resolv_str_to_dn_label() API about trailing zero
authorWilly Tarreau <w@1wt.eu>
Thu, 14 Oct 2021 05:49:49 +0000 (07:49 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 3 Nov 2021 10:12:44 +0000 (11:12 +0100)
commit0bf6947f328cfddf320fe81d6c6df94990dad8ad
treefb22a94e548f2aed6fe2f0b733731d67e51299e6
parentafac744e1c0635d137869874abb27cb251f71390
MINOR: resolvers: fix the resolv_str_to_dn_label() API about trailing zero

This function is bogus at the API level: it demands that the input string
is zero-terminated *and* that its length *including* the trailing zero is
passed on input. While that already looks smelly, the trailing zero is
copied as-is, and is then explicitly replaced with a zero... Not only
all callers have to pass hostname_len+1 everywhere to work around this
absurdity, but this requirement causes a bug in the do-resolve() action
that passes random string lengths on input, and that will be fixed on a
subsequent patch.

Let's fix this API issue for now.

This patch will have to be backported, and in versions 2.3 and older,
the function is in dns.c and is called dns_str_to_dn_label().

(cherry picked from commit bf9498a31beb41078ebf257c54b7acb879bcb98b)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit c1c765f27d2a31f90ffe233d218282aa16d52e7c)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
src/dns.c
src/server.c