From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8545 Path: news.gmane.org!not-for-mail From: Julien Ramseier Newsgroups: gmane.linux.lib.musl.general Subject: getaddrinfo usage with wrong ip family Date: Tue, 22 Sep 2015 16:40:30 +0200 Message-ID: <06898546-AC9C-40F0-A2F5-2F1CC02E185C@gmail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2102\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_62F7DD4B-6054-45BE-A33F-8801906C47B9" X-Trace: ger.gmane.org 1442932854 5440 80.91.229.3 (22 Sep 2015 14:40:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 22 Sep 2015 14:40:54 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-8557-gllmg-musl=m.gmane.org@lists.openwall.com Tue Sep 22 16:40:54 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1ZeOkX-0004rD-IU for gllmg-musl@m.gmane.org; Tue, 22 Sep 2015 16:40:53 +0200 Original-Received: (qmail 30112 invoked by uid 550); 22 Sep 2015 14:40:50 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 30030 invoked from network); 22 Sep 2015 14:40:43 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-type:subject:message-id:date:to:mime-version; bh=SVFJwh4CHZfIgfjpgyVkCISrjKEuofg32HnbsH3+ym0=; b=gKblZZdeiIWlajEVqjRQW8qyCxfx5us4EpEO6QGomOJuzYyy4EcR7wfwLvkB4I+22a ctvUSC9NoiXxLX7rAbK/HL4btAS6+kTMJScJ6C45RAgFTvzA+WBTB6JUmju7yjEHSo/F qfovvm8gQIOD7/lFyISoTR2SKFGEWB4AeL7Wmp6VfTYjd/yUzoHsSxy2LZW0k2Qq/VI1 pb9pMXzcxzsmic8KNvIPzML9U7gcD+l/MlGeLBNOLuULADN/L7wx3z3Q2WYla+QyhKW5 t0oF51MO/wenk5gUYxTY5Kb6qFAWli3627uNJ0Y1OTic9f1ktAya9Xnr0FTtqYJtJcq2 4j9Q== X-Received: by 10.180.107.1 with SMTP id gy1mr21617972wib.56.1442932832428; Tue, 22 Sep 2015 07:40:32 -0700 (PDT) X-Mailer: Apple Mail (2.2102) Xref: news.gmane.org gmane.linux.lib.musl.general:8545 Archived-At: --Apple-Mail=_62F7DD4B-6054-45BE-A33F-8801906C47B9 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hello, I discovered a potential problem in getaddrinfo/__lookup_name. When calling getaddrinfo with an IP string not matching the specified = family, name_from_numeric() in __lookup_name() will not recognize it and the=20 external dns resolver will be used. So the following code: const struct addrinfo hints =3D { .ai_flags =3D AI_ADDRCONFIG, .ai_family =3D AF_INET, .ai_socktype =3D SOCK_STREAM, }; getaddrinfo("::1", NULL, &hints, &result); will actually succeed instead of returning EAI_NONAME, and perform a "A ::1" query. Some misbehaving dns servers will then answer with 0.0.0.1. I don=E2=80=99t know if this behavior is desirable. If not, I=E2=80=99m = still not sure where this should be fixed. Maybe should we prevent sending A and AAAA dns queries with IP as hostname in __res_mkquery() ? =E2=80=94 Julien --Apple-Mail=_62F7DD4B-6054-45BE-A33F-8801906C47B9 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Hello,

I = discovered a potential problem in getaddrinfo/__lookup_name.
When calling getaddrinfo  with an IP string not matching = the specified family,
name_from_numeric() in = __lookup_name() will not recognize it and the 
external dns resolver will be used.

So the following code:

const struct addrinfo hints =3D = {
  =   .ai_flags =3D AI_ADDRCONFIG,
    .ai_family =3D = AF_INET,
    .ai_socktype =3D SOCK_STREAM,
};

getaddrinfo("::1", NULL, &hints, = &result);

will actually succeed instead of returning = EAI_NONAME,
and perform a "A ::1" query.
Some misbehaving = dns servers will then answer with 0.0.0.1.

I don=E2=80=99t know if this behavior = is desirable. If not, I=E2=80=99m still not sure
where this should be fixed. Maybe should we prevent = sending
A and AAAA dns queries with IP as hostname = in __res_mkquery() ?

=E2=80=94
Julien

= --Apple-Mail=_62F7DD4B-6054-45BE-A33F-8801906C47B9--