Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Thu, 20 Oct 2022 19:55:22 -0400
From: Rich Felker <dalias@...c.org>
To: Tom Shen <sjiagc.dev@...il.com>
Cc: musl@...ts.openwall.com
Subject: Re: gethostbyname2_r returns invalid IPv6 address if DNS
 server replies IPv4 address

On Fri, Oct 21, 2022 at 01:25:50AM +0800, Tom Shen wrote:
> I tested the fix in your earlier email locally with my own test code and
> getent in Alpine Linux 3.16.2. They both crashed. After debugging, I found
> in gethostbyname2_r we should return non-zero if no address is returned.
> Then gethostbyname2 will return NULL. I also check the Linux doc, it says:
> 
> > Return Value
> > The gethostbyname() and gethostbyaddr() functions return the hostent
> structure or *a NULL pointer if an error occurs*. On error, the h_errno
> variable holds an error number. When non-NULL, the return value may point
> at static data, see the notes below.
> 
> Based on your patch (except the "for (i=nq-1; i>=0; i--)"), I made a minor
> change to address it. Tested with command getent hosts, it works well with
> my CoreDNS. Although the h_errno is better to be NO_DATA rather than
> HOST_NOT_FOUND, I think it's not a big issue.
> 
> The diff file attached.

This is a different bug you've found in gethostbyname2. It seems it
was not updated when commit f081d5336a80b68d3e1bed789cc373c5c3d6699b
fixed the return behavior of gethostbyname2_r to treat NODATA and
NxDomain as success conditions rather than errors. Attached patch
should fix it right.

Rich

View attachment "0001-fix-return-value-of-gethostby-name-2-addr-with-no-re.patch" of type "text/plain" (1715 bytes)

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.