<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
Appears to be a duplicate, a reply was sent out to the original:<br>
<a class="moz-txt-link-freetext" href="https://lists.haxx.se/pipermail/c-ares/2022-April/000035.html">https://lists.haxx.se/pipermail/c-ares/2022-April/000035.html</a><br>
<br>
<div class="moz-cite-prefix">On 5/2/22 8:08 PM, Dmitry Karpov via
c-ares wrote:<br>
</div>
<blockquote type="cite"
cite="mid:BYAPR01MB5606353BDC1D78B35DAB5798C3C09@BYAPR01MB5606.prod.exchangelabs.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style>@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;}p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}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]-->
<div class="WordSection1">
<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>
</div>
<br>
<fieldset class="moz-mime-attachment-header"></fieldset>
</blockquote>
<br>
</body>
</html>