BUG/MEDIUM: resolvers: use correct storage for the target address
authorWilly Tarreau <w@1wt.eu>
Thu, 14 Oct 2021 20:30:38 +0000 (22:30 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 3 Nov 2021 10:33:19 +0000 (11:33 +0100)
commit342b785ad5ccbcadf7d60b881c349c21b2d7d6d4
treec2bf3d831977d16ef93af6e49053fc0759498fc4
parentf7ce8a4d9e4c94c8280aafdec09fd1c8c7714bef
BUG/MEDIUM: resolvers: use correct storage for the target address

The struct resolv_answer_item contains an address field of type
"sockaddr" which is only 16 bytes long, but which is used to store
either IPv4 or IPv6. Fortunately, the contents only overlap with
the "target" field that follows it and that is large enough to
absorb the extra bytes needed to store AAAA records. But this is
dangerous as just moving fields around could result in memory
corruption.

The fix uses a union and removes the casts that were used to hide
the problem.

Older versions need to be checked and possibly fixed. This needs
to be backported anyway.

(cherry picked from commit b4ca0195a9591614bfcebe9b7fe80c1ce9f94d8d)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit c54aabaf7c73e563a4cfdef760e2ae767612c601)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
include/haproxy/dns-t.h
src/dns.c