Skip to content

Commit df94703

Browse files
committed
Null deref if ares_getaddrinfo() is terminated with ares_destroy()
ares_freeaddrinfo() was not checking for a Null ptr during cleanup of an aborted query. Once that was resolved it uncovered another possible issue with multiple simultaneous underlying queries being outstanding and possibly prematurely cleaning up the handle. Reported By: Michael Kourlas Fix By: Brad House (@bradh352)
1 parent fa903fd commit df94703

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/lib/ares_freeaddrinfo.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ void ares__freeaddrinfo_nodes(struct ares_addrinfo_node *head)
5151

5252
void ares_freeaddrinfo(struct ares_addrinfo *ai)
5353
{
54+
if (ai == NULL)
55+
return;
5456
ares__freeaddrinfo_cnames(ai->cnames);
5557
ares__freeaddrinfo_nodes(ai->nodes);
5658
ares_free(ai);

src/lib/ares_getaddrinfo.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -544,11 +544,6 @@ static void host_callback(void *arg, int status, int timeouts,
544544
{
545545
addinfostatus = ares__parse_into_addrinfo(abuf, alen, hquery->ai);
546546
}
547-
else if (status == ARES_EDESTRUCTION)
548-
{
549-
end_hquery(hquery, status);
550-
return;
551-
}
552547

553548
if (!hquery->remaining)
554549
{
@@ -566,6 +561,13 @@ static void host_callback(void *arg, int status, int timeouts,
566561
{
567562
next_lookup(hquery, status);
568563
}
564+
else if (status == ARES_EDESTRUCTION)
565+
{
566+
/* NOTE: Could also be ARES_EDESTRUCTION. We need to only call this
567+
* once all queries (there can be multiple for getaddrinfo) are
568+
* terminated. */
569+
end_hquery(hquery, status);
570+
}
569571
else
570572
{
571573
end_hquery(hquery, status);

0 commit comments

Comments
 (0)