This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/12734] New: resolver failures without even sending a query.
- From: "matthias.andree at gmx dot de" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: Thu, 5 May 2011 13:31:59 +0000
- Subject: [Bug libc/12734] New: resolver failures without even sending a query.
- Auto-submitted: auto-generated
http://sourceware.org/bugzilla/show_bug.cgi?id=12734
Summary: resolver failures without even sending a query.
Product: glibc
Version: 2.13
Status: NEW
Severity: critical
Priority: P2
Component: libc
AssignedTo: drepper.fsp@gmail.com
ReportedBy: matthias.andree@gmx.de
Created attachment 5707
--> http://sourceware.org/bugzilla/attachment.cgi?id=5707
code to demonstrate the bug
(I've observed this on eglibc 2.13 and glibc 2.11.3 and confirmed it's still
present in Git.)
Problem: res_search() can return -1 with h_errno == HOST_NOT_FOUND without ever
having attempted a nameserver query even when it should have sent one.
In particular, this affects hostname resolution of "localhost" (without dots)
if RES_DEFNAMES isn't set. (Use case: a security-sensitive application strips
this flag to avoid the domain search and to avoid getting bogus
localhost.example.org results that might not point to 127.0.0.1/::1.)
Pseudo code, without error checking:
res_init();
_res.options &= ~RES_DEFNAMES;
int result = res_search("localhost", C_IN, T_A, buf, sizeof buffer);
This is an important portability issue from BSD or Solaris to Linux and
affects, for instance, Postfix 2.8.X.
Compare the glibc source code lines 323 ff.
<http://sourceware.org/git/?p=glibc.git;a=blob;f=resolv/res_query.c;h=5ff352e2fc6056bad92238df1fb0c826f48a2f51;hb=HEAD#l323>
against FreeBSD, lines 371 ff. in
<http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libc/resolv/res_query.c?annotate=1.6;only_with_tag=MAIN>.
I've attached a test program, show-resolv.c, to demonstrate the problem.
To compile: gcc -ggdb3 -O -std=gnu99 -pedantic -Wall -o show-resolv
show-resolv.c -lresolv
To run: strace -e recv,send,recvfrom,sendto ./show-resolv
You will see that no DNS packets are sent to the nameserver configured in
/etc/resolv.conf.
Actual output (no send/recv stuff!):
$ strace -e recv,send,recvfrom,sendto ./show-resolv
default _res.options = 802C1
stripped _res.options = 80241
res search result: -1, h_errno: 1 (Unknown host)
Expected output:
$ strace -e recv,send,recvfrom,sendto ./show-resolv
default _res.options = 802C1
stripped _res.options = 80241
sendto(3, "\34\264\1\0\0\1\0\0\0\0\0\0\tlocalhost\0\0\1\0\1", 27, MSG_NOSIGNAL,
NULL, 0) = 27
recvfrom(3,
"\34\264\205\200\0\1\0\1\0\0\0\0\tlocalhost\0\0\1\0\1\300\f\0\1\0"..., 512, 0,
{sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("192.168.0.4")},
[16]) = 43
res search result: 43
Of course the recvfrom details may differ with /etc/resolv.conf configuration.
And instead of 43, any positive number that makes it plausible we've received a
successful reply to a DNS query for localhost IN A is valid, should there be
gratuitious other records returned from the name server.
Please fix the resolver so that it actually sends a query for bare hostnames
(without any dots, inner or trailing), localhost is a valid TLD.
--
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.