"stale-answer-client-timeout" > 0 can cause crashes when prefetch is enabled
named
can crash in the following scenario:
-
Assume that
stale-answer-client-timeout
is set to a positive value and that in the course of resolving acname.example/A
query, the following records were cached:cname.example. CNAME a.example. ; TTL=10 a.example. A 192.0.2.1 ; TTL=12
-
10 seconds pass, causing the relevant cache contents to become:
cname.example. CNAME a.example. ; expired a.example. A 192.0.2.1 ; TTL=2
-
The resolver is queried for
cname.example/A
again. -
cname.example/CNAME
is expired, so recursion starts. As a part of this process, theDNS_FETCHOPT_TRYSTALE_ONTIMEOUT
flag is set inclient->query.fetchoptions
. -
The authoritative response for
cname.example/CNAME
arrives beforea.example/A
expires from the cache. -
Query processing is restarted for
a.example/A
(the CNAME target). -
a.example/A
is found in the cache with a positive TTL which falls below the default prefetch trigger (2 seconds). -
A prefetch for
a.example/A
is started withDNS_FETCHOPT_TRYSTALE_ONTIMEOUT
still being set. This causes the "try stale" timer to be started for the prefetch query. -
No response to the prefetch query arrives before the "try stale" timeout fires.
-
prefetch_done()
is called and is passed an event of typeDNS_EVENT_TRYSTALE
. -
The
REQUIRE(event->ev_type == DNS_EVENT_FETCHDONE);
assertion fails, causingnamed
to crash.