Skip to content

Commit b949cc3

Browse files
ki11roybradh352
authored andcommitted
Fix leak and crash in ares_parse_a/aaaa_reply (#264)
* fix leak if naddress of particular type found * fix segfault when wanted ttls count lesser than count of result records * add fuzzer input files that trigger problems (from #263) Reported-By: David Drysdale (@daviddrysdale) Fix-By: Andrew Selivanov (@ki11roy)
1 parent 5dd3629 commit b949cc3

13 files changed

+14
-4
lines changed

ares_parse_a_reply.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ int ares_parse_a_reply(const unsigned char *abuf, int alen,
7171

7272
if (naddrttls)
7373
{
74-
*naddrttls = naddrs;
74+
*naddrttls = 0;
7575
}
7676

7777
return status;
@@ -162,7 +162,7 @@ int ares_parse_a_reply(const unsigned char *abuf, int alen,
162162
memcpy(hostent->h_addr_list[i],
163163
&(((struct sockaddr_in *)next->ai_addr)->sin_addr),
164164
sizeof(struct in_addr));
165-
if (naddrttls)
165+
if (naddrttls && i < *naddrttls)
166166
{
167167
if (next->ai_ttl > cname_ttl)
168168
addrttls[i].ttl = cname_ttl;
@@ -177,6 +177,10 @@ int ares_parse_a_reply(const unsigned char *abuf, int alen,
177177
}
178178
next = next->ai_next;
179179
}
180+
if (i == 0)
181+
{
182+
ares_free(addrs);
183+
}
180184
}
181185

182186
if (host)

ares_parse_aaaa_reply.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ int ares_parse_aaaa_reply(const unsigned char *abuf, int alen,
7373

7474
if (naddrttls)
7575
{
76-
*naddrttls = naddrs;
76+
*naddrttls = 0;
7777
}
7878

7979
return status;
@@ -164,7 +164,7 @@ int ares_parse_aaaa_reply(const unsigned char *abuf, int alen,
164164
memcpy(hostent->h_addr_list[i],
165165
&(((struct sockaddr_in6 *)next->ai_addr)->sin6_addr),
166166
sizeof(struct ares_in6_addr));
167-
if (naddrttls)
167+
if (naddrttls && i < *naddrttls)
168168
{
169169
if(next->ai_ttl > cname_ttl)
170170
addrttls[i].ttl = cname_ttl;
@@ -179,6 +179,11 @@ int ares_parse_aaaa_reply(const unsigned char *abuf, int alen,
179179
}
180180
next = next->ai_next;
181181
}
182+
183+
if (i == 0)
184+
{
185+
ares_free(addrs);
186+
}
182187
}
183188

184189
if (host)

test/fuzzcheck.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/sh
2+
set -e
23
# Check that all of the base fuzzing corpus parse without errors
34
./aresfuzz fuzzinput/*
45
./aresfuzzname fuzznames/*
32 Bytes
Binary file not shown.
242 Bytes
Binary file not shown.
1.64 KB
Binary file not shown.
1.92 KB
Binary file not shown.
51.3 KB
Binary file not shown.
789 Bytes
Binary file not shown.
44 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)