Bug 7060 - getaddrinfo() with hints.ai_family = PF_UNSPEC changes behavior in glibc 2.9
Summary: getaddrinfo() with hints.ai_family = PF_UNSPEC changes behavior in glibc 2.9
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Ulrich Drepper
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-01 14:10 UTC by Bernhard Rosenkraenzer
Modified: 2014-07-01 21:02 UTC (History)
4 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Last reconfirmed:
fweimer: security-


Attachments
Patch that fixes it by reverting to 2.8 behavior (3.20 KB, patch)
2008-12-01 15:51 UTC, Bernhard Rosenkraenzer
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Bernhard Rosenkraenzer 2008-12-01 14:10:29 UTC
Up until glibc 2.8, this would work and return the IPv4 address:

struct addrinfo hints, *ai, *aitop;
int err;
char *host=strdup("www.google.com");
char *port=strdup("80");
memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
err=getaddrinfo(host, port, &hints, &aitop);
if(err)
    fprintf(stderr, "Error: %s", strerror(err));


In glibc 2.9, it returns Error: Name or service not known
Changing hints.ai_family to PF_INET makes it work with glibc 2.9.

I'm not sure which behavior is correct, but 2.9's does break a few 
applications (ncftp for one).

This is on an IPv4 machine (with an IPv6 address for localhost set); 
nsswitch.conf has "hosts: files mdns dns"
Comment 1 Bernhard Rosenkraenzer 2008-12-01 14:17:55 UTC
This works as before in 2.9 for hostnames that are listed in /etc/hosts; it 
only fails if it has to look up stuff on the DNS.

The DNS itself works (applications that don't use getaddrinfo(), such as host, 
ping, konqueror, firefox, ... keep working).
Comment 2 Jakub Jelinek 2008-12-01 14:31:29 UTC
What nameserver are you using?  Most likely a DNS server bug.
Comment 3 Bernhard Rosenkraenzer 2008-12-01 15:40:43 UTC
The DNS is the internal DNS of a Netopia 3346N-VGx DSL modem, revision 
7.7.4r1.

Modifying /etc/resolv.conf to point at a Linux box running bind 9.5.x does fix 
it.

A workaround is probably needed though, Netopia 3346N-VGx DSL modems come with 
every Swisscom DSL line for free...
Comment 4 Bernhard Rosenkraenzer 2008-12-01 15:51:57 UTC
Created attachment 3084 [details]
Patch that fixes it by reverting to 2.8 behavior

The attached patch fixes it by reverting most of getaddrinfo.c to what it was
in glibc 2.8 -- not quite the right thing to do, but I can confirm it fixes the
problem.
Comment 5 Jan de Groot 2008-12-03 07:43:09 UTC
I'm also facing this bug when using the Hotbrick LB2 as DNS server. Disabling
ipv6 on my system fixes this problem. Installing a local recursor like
pdns-recursor also fixes this issue, so it's related to broken DNS servers.

with pdns-recursor:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 21282
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:
;redhat.com.			IN	AAAA

;; AUTHORITY SECTION:
redhat.com.		600	IN	SOA	ns1.redhat.com. noc.redhat.com. 2008112502 3600 1800
604800 86400

Result with Hotbrick LB2:
;; ->>HEADER<<- opcode: QUERY, status: NOTIMP, id: 51617
;; flags: rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;redhat.com.			IN	AAAA

The hotbrick LB2 returns NOTIMP, which violates the RFC.
Comment 6 Petr Baudis 2009-01-09 04:51:43 UTC
Note that a simpler workaround is to just disable the gethostbyname4() lookup
method being exported, as Jakub Jelinek did for Fedora (and me doing for SUSE now):

http://pasky.or.cz/~pasky/dev/glibc/glibc-2.10-dns-no-gethostbyname4.diff
Comment 7 Jakub Jelinek 2009-01-09 08:09:40 UTC
Also note that it is just a temporary measure, Ulrich plans to work on the
resolv code soon.
Comment 8 Andreas Schwab 2010-08-31 11:09:53 UTC
Should be fixed in 2.10.