resolve: fix potential memleak and use-after-free
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 5 Feb 2022 12:37:01 +0000 (21:37 +0900)
committerLuca Boccassi <bluca@debian.org>
Tue, 15 Feb 2022 01:13:47 +0000 (01:13 +0000)
commit8baf04a6588bd392f606a3d55b0711cdd00b4b80
treedff597ee460b6de05e914bd4fef360cd93597597
parent356b1ee1febeecf636eec6b7e08036603bf760d5
resolve: fix potential memleak and use-after-free

When stub stream is closed early, then queries associated to the stream
are freed. Previously, the timer event source for queries may not be
disabled, hence may be triggered with already freed query.
See also dns_stub_stream_complete().

Note that we usually not set NULL or zero when freeing simple objects.
But, here DnsQuery is large and complicated object, and the element may
be referenced in subsequent freeing process in the future. Hence, for
safety, let's set NULL to the pointer.

(cherry picked from commit 73bfd7be042cc63e7649242b377ad494bf74ea4b)
(cherry picked from commit d82bd80cf4e7659906a502735b20a45964b55a88)
src/resolve/resolved-dns-query.c