<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Thanks a lot, Brad!<br>
I didn’t receive your reply somehow.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> Brad House <brad@brad-house.com> <br>
<b>Sent:</b> Monday, May 2, 2022 5:11 PM<br>
<b>To:</b> c-ares discussions <c-ares@lists.haxx.se><br>
<b>Cc:</b> Dmitry Karpov <dkarpov@roku.com><br>
<b>Subject:</b> Re: Last bad IPv6 query response can make c-ares to report resolution failure even if there is previously successful IPv4 response<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-bottom:12.0pt">Appears to be a duplicate, a reply was sent out to the original:<br>
<a href="https://lists.haxx.se/pipermail/c-ares/2022-April/000035.html">https://lists.haxx.se/pipermail/c-ares/2022-April/000035.html</a><o:p></o:p></p>
<div>
<p class="MsoNormal">On 5/2/22 8:08 PM, Dmitry Karpov via c-ares wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal">Hi,<o:p></o:p></p>
<p class="MsoNormal"><br>
I recently stepped on an issue with curl using c-ares ares_getaddrinfo() with PF_UNSPEC family, when AAAA response from DNS server contained some bad data resulting into ARES_EBADRESP status code whereas A response was good.<br>
<br>
The problem was that when AAAA response was the last received, it made c-ares to ignore previously received good A response and fail the host resolution with ARES_EBADRESP status code.<br>
But if A response was the last received, then c-ares ignored the bad AAAA response and the host resolution was successful.<br>
<br>
I looked at the c-ares code, and found the problem in the host_callback() function<span style="font-size:9.5pt;font-family:Consolas;color:#880000">
</span> (src\lib\ares_getaddrinfo.c: 528)<br>
<br>
static void host_callback(void *arg, int status, int timeouts,<o:p></o:p></p>
<p class="MsoNormal"> unsigned char *abuf, int alen)<o:p></o:p></p>
<p class="MsoNormal">{<o:p></o:p></p>
<p class="MsoNormal"> struct host_query *hquery = (struct host_query*)arg;<o:p></o:p></p>
<p class="MsoNormal"> int addinfostatus = ARES_SUCCESS;<o:p></o:p></p>
<p class="MsoNormal"> hquery->timeouts += timeouts;<o:p></o:p></p>
<p class="MsoNormal"> hquery->remaining--;<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"> if (status == ARES_SUCCESS)<o:p></o:p></p>
<p class="MsoNormal"> {<o:p></o:p></p>
<p class="MsoNormal"> addinfostatus = ares__parse_into_addrinfo(abuf, alen, 1, hquery->port, hquery->ai);<o:p></o:p></p>
<p class="MsoNormal"> }<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"> if (!hquery->remaining)<o:p></o:p></p>
<p class="MsoNormal"> {<o:p></o:p></p>
<p class="MsoNormal"> if (addinfostatus != ARES_SUCCESS && addinfostatus != ARES_ENODATA)<o:p></o:p></p>
<p class="MsoNormal"> {<o:p></o:p></p>
<p class="MsoNormal"> /* error in parsing result e.g. no memory */<o:p></o:p></p>
<p class="MsoNormal"> end_hquery(hquery, addinfostatus);<o:p></o:p></p>
<p class="MsoNormal"> }<o:p></o:p></p>
<p class="MsoNormal"> else if (hquery->ai->nodes) <o:p></o:p></p>
<p class="MsoNormal"> …<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">When there are no remaining queries, the ARES_EBADRESP parsing error is reported immediately, even though the previous query might be successful.<br>
<br>
I suggest the following fix for this problem:<br>
<br>
if (!hquery->remaining)<o:p></o:p></p>
<p class="MsoNormal"> {<o:p></o:p></p>
<p class="MsoNormal"> if (addinfostatus != ARES_SUCCESS && addinfostatus != ARES_ENODATA)<o:p></o:p></p>
<p class="MsoNormal"> {<o:p></o:p></p>
<p class="MsoNormal"> /* error in parsing result e.g. no memory */<o:p></o:p></p>
<p class="MsoNormal"> if (addinfostatus == ARES_EBADRESP && hquery->ai->nodes)<o:p></o:p></p>
<p class="MsoNormal"> {<o:p></o:p></p>
<p class="MsoNormal"> /* We got a bad response from the server, but at least one query<o:p></o:p></p>
<p class="MsoNormal"> * ended with ARES_SUCCESS */<o:p></o:p></p>
<p class="MsoNormal"> end_hquery(hquery, ARES_SUCCESS);<o:p></o:p></p>
<p class="MsoNormal"> }<o:p></o:p></p>
<p class="MsoNormal"> else<o:p></o:p></p>
<p class="MsoNormal"> {<o:p></o:p></p>
<p class="MsoNormal"> end_hquery(hquery, addinfostatus);<o:p></o:p></p>
<p class="MsoNormal"> }<o:p></o:p></p>
<p class="MsoNormal"> }<br>
<span style="font-size:9.5pt;font-family:Consolas;color:black"><br>
</span>I am also attaching a patch file with the potential fix.<br>
<br>
Thanks,<br>
Dmitry Karpov<o:p></o:p></p>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
</blockquote>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>