src/types.c: Do not crash when one of several addr subqueries fails
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 19 Feb 2015 01:05:33 +0000 (01:05 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 21 Feb 2015 11:41:46 +0000 (11:41 +0000)
commitf80690def49ab15ee32f01aaa3d2577807fef4ce
treef6c8336c5f9796cb91978a50c61ca42b2c37a51d
parenta28e59c806fc4219f5fa3dbf71df6ecd7cf4b9d4
src/types.c: Do not crash when one of several addr subqueries fails

If a name passed to the addr lookup machinery (eg, passed to an
adns_r_addr query, or resulting from a dereferencing query like
adns_r_mx) has addresses for one address family (eg IPv4) but
temporary failure for another (eg IPv6) then adns might (would
usually) crash.

This is because icb_hostaddr would fail to reset the accumulated addrs
pointer to 0 after freeing it, and then set naddrs to -1.  The crash
would occur in makefinal, which would attempt to arrange to copy -1
elements into the unifed output buffer.

If the second AF gives a permanent error, the relevant part of the
answer would contain an invalid (freed) pointer, with a zero length.
The result during makefinal_query would be to allocate a zero length
`block' in the unified output result buffer and put the pointer to
that in the answer for the application, which is a violation of the
promised API.

This bug was introduced with IPv6 support (in 1.5.0, in commit
2ca5496dfc95).

A test case for this bug will be introduced shortly.

Reported-by: Chris Burton of 8086.net
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
changelog
src/types.c