mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] Behavior change in getaddrbyname() with AF_UNSPEC
@ 2023-01-14 22:56 Barry Bond
  2023-01-18 15:26 ` Rich Felker
  0 siblings, 1 reply; 5+ messages in thread
From: Barry Bond @ 2023-01-14 22:56 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 1277 bytes --]

This is related to this change:  https://git.musl-libc.org/cgit/musl/commit/?id=5cf1ac2443ad0dba263559a3fe043d929e0e5c4c made back in 2020.

In the repro case, getaddrbyname() with AF_UNSPEC sends out two requests, but only gets back a single response, with the ipv4 address.   There is no ipv6 on the network.

name_from_dns() contains the relevant code.  After __res_msend_rc() returns, 'nq' is 2, and 'alens' is [96, 0], indicating that there was an ipv4 response of 96 bytes, but no response for ipv6.  Then the validation code runs:

                for (i=0; i<nq; i++) {
                                if (alens[i] < 4 || (abuf[i][3] & 15) == 2) return EAI_AGAIN;
                                if ((abuf[i][3] & 15) == 3) return 0;
                                if ((abuf[i][3] & 15) != 0) return EAI_FAIL;
                }

and the result is EAI_AGAIN, because alens[1]==0.

Before this patch, the code would have parsed the ipv4 response via __dns_parse(), failed to parse the empty second response because alens[1]<12, and the function would return with ctx.cnt==1.

I propose adding one new check at the top of the for() loop:
                if (alens[i] == 0) continue; /* response timed out */

Thanks!
Barry - Microsoft Azure Sphere


[-- Attachment #2: Type: text/html, Size: 4566 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-01-24  8:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-14 22:56 [musl] Behavior change in getaddrbyname() with AF_UNSPEC Barry Bond
2023-01-18 15:26 ` Rich Felker
2023-01-19 14:58   ` [musl] RE: [EXTERNAL] " Barry Bond
2023-01-23  1:34     ` [musl] " Barry Bond
2023-01-24  8:54       ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).