BUG/MINOR: resolvers: always normalize FQDN from response
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Wed, 10 Sep 2025 16:30:19 +0000 (18:30 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 1 Oct 2025 14:48:35 +0000 (16:48 +0200)
commite8600734c2c75b2de1e37b37e03c4b3e04ae1ad7
tree0c6d4ec78baf5599e899ba7876d4f993ec4439f6
parent8d7921e980b3fdab7c54ebd4cb3cb320b371e6bb
BUG/MINOR: resolvers: always normalize FQDN from response

RFC1034 states the following:

By convention, domain names can be stored with arbitrary case, but
domain name comparisons for all present domain functions are done in a
case-insensitive manner, assuming an ASCII character set, and a high
order zero bit. This means that you are free to create a node with
label "A" or a node with label "a", but not both as brothers; you could
refer to either using "a" or "A".

In practice, most DNS resolvers normalize domain labels (i.e., convert
them to lowercase) before performing searches or comparisons to ensure
this requirement is met.

While HAProxy normalizes the domain name in the request, it currently
does not do so for the response. Commit 75cc653 ("MEDIUM: resolvers:
replace bogus resolv_hostname_cmp() with memcmp()") intentionally
removed the `tolower()` conversion from `resolv_hostname_cmp()` for
safety and performance reasons.

This commit re-introduces the necessary normalization for FQDNs received
in the response. The change is made in `resolv_read_name()`, where labels
are processed as an unsigned char string, allowing `tolower()` to be
applied safely. Since a typical FQDN has only 3-4 labels, replacing
`memcpy()` with an explicit copy that also applies `tolower()` should
not introduce a significant performance degradation.

This patch addresses the rare edge case, as most resolvers perform this
normalization themselves.

This fixes the GitHub issue #3102. This fix may be backported in all stable
versions since 2.5 included 2.5.

(cherry picked from commit f8acac653e104e90f06dd8c774ccd9d14b531546)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 877a36ef246372d5c4ac6471b2961700737a9a73)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 1fef81acbb94f9026156123bb4ff394b6ead4c52)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
src/resolvers.c