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