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-- From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8546 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: getaddrinfo usage with wrong ip family Date: Tue, 22 Sep 2015 11:16:25 -0400 Message-ID: <20150922151625.GX17773@brightrain.aerifal.cx> References: <06898546-AC9C-40F0-A2F5-2F1CC02E185C@gmail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1442935065 10425 80.91.229.3 (22 Sep 2015 15:17:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 22 Sep 2015 15:17:45 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-8558-gllmg-musl=m.gmane.org@lists.openwall.com Tue Sep 22 17:17:45 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 1ZePKC-0003lE-LZ for gllmg-musl@m.gmane.org; Tue, 22 Sep 2015 17:17:44 +0200 Original-Received: (qmail 26552 invoked by uid 550); 22 Sep 2015 15:16:39 -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 26465 invoked from network); 22 Sep 2015 15:16:38 -0000 Content-Disposition: inline In-Reply-To: <06898546-AC9C-40F0-A2F5-2F1CC02E185C@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:8546 Archived-At: On Tue, Sep 22, 2015 at 04:40:30PM +0200, Julien Ramseier wrote: > 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 = { > .ai_flags = AI_ADDRCONFIG, > .ai_family = AF_INET, > .ai_socktype = 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’t know if this behavior is desirable. If not, I’m 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() ? Sometime (it's been "soon" for a long time) I intend to add IDN support, so the same place that goes would be the natural place to pre-validate strings before sending them off in DNS queries. But I'm not sure what the right filtering would be. Another approach might be having __lookup_numeric always parse with AF_UNSPEC, but return error rather than 0 results if the resulting family does not match the requested family. Anyone else have opinions on these ideas? Rich From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8558 Path: news.gmane.org!not-for-mail From: Julien Ramseier Newsgroups: gmane.linux.lib.musl.general Subject: Re: getaddrinfo usage with wrong ip family Date: Thu, 24 Sep 2015 12:27:22 +0200 Message-ID: <71B72D33-A1D4-4B23-BFEB-6BFA01DF7523@gmail.com> References: <06898546-AC9C-40F0-A2F5-2F1CC02E185C@gmail.com> <20150922151625.GX17773@brightrain.aerifal.cx> 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=_4DFE8D35-A3AF-42DA-8D08-E9D57FBDCA3F" X-Trace: ger.gmane.org 1443090473 13053 80.91.229.3 (24 Sep 2015 10:27:53 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 24 Sep 2015 10:27:53 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-8570-gllmg-musl=m.gmane.org@lists.openwall.com Thu Sep 24 12:27:53 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 1Zf3kZ-0003ZD-NR for gllmg-musl@m.gmane.org; Thu, 24 Sep 2015 12:27:39 +0200 Original-Received: (qmail 1353 invoked by uid 550); 24 Sep 2015 10:27:36 -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 1335 invoked from network); 24 Sep 2015 10:27:36 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-type:message-id:mime-version:subject:date:references :to:in-reply-to; bh=Y3D82Gxb9hIo2zCKmVWHOIqS+3XRaIYK3bDh9emuqf4=; b=aTdxOJNJRr0s7gyKqD0T6BKDpiqWXt0LD5lV+cmeXpAGOk7EnYlQrsbTMo0qrmm/Sn ntmzaDPTcK5KyY83d0H4HDY4gjH5rL6M+ZqjLMEDqLu5wIzxdQimJjVcUYzI63CGQB1X r4CMMKpukl631iwO5+wPxWXUi09fHO+s6ktRq3u7fYgZgWSZf5S3xeItpvD9poHtoorf TBLKQY9xUASxcbqNPU8f+hOIVHw0VX9GeEYSQEchp75ct1zZbaWX/VHet7fHMl3LRs7t JOLEtuuE5IGidiu60Mu8N9p1tJV53G2HeL/8l2KVfEUkl/EZv+OURxHE6wyInQYEPO8l KsPg== X-Received: by 10.194.104.39 with SMTP id gb7mr41217454wjb.150.1443090444705; Thu, 24 Sep 2015 03:27:24 -0700 (PDT) In-Reply-To: <20150922151625.GX17773@brightrain.aerifal.cx> X-Mailer: Apple Mail (2.2102) Xref: news.gmane.org gmane.linux.lib.musl.general:8558 Archived-At: --Apple-Mail=_4DFE8D35-A3AF-42DA-8D08-E9D57FBDCA3F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > Le 22 sept. 2015 =C3=A0 17:16, Rich Felker a =C3=A9cri= t : >=20 > Another approach might be having __lookup_numeric always parse with > AF_UNSPEC, but return error rather than 0 results if the resulting > family does not match the requested family. This seems the simplest solution in the meantime. Here=E2=80=99s the patch I applied to my trunk. =E2=80=94 Julien= --Apple-Mail=_4DFE8D35-A3AF-42DA-8D08-E9D57FBDCA3F Content-Type: multipart/mixed; boundary="Apple-Mail=_87DFA2CB-04EC-4DA6-8576-E815B15637D1" --Apple-Mail=_87DFA2CB-04EC-4DA6-8576-E815B15637D1 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
Le 22 sept. 2015 =C3=A0 17:16, Rich Felker <dalias@libc.org> a = =C3=A9crit :

Another approach might be = having __lookup_numeric always parse with
AF_UNSPEC, but return error rather than 0 = results if the resulting
family does not match the = requested family.

This seems the simplest solution in the meantime.

Here=E2=80=99s the patch I applied = to my trunk.

= --Apple-Mail=_87DFA2CB-04EC-4DA6-8576-E815B15637D1 Content-Disposition: attachment; filename=lookup_ipliteral-error-on-incorrect-family.patch Content-Type: application/octet-stream; name="lookup_ipliteral-error-on-incorrect-family.patch" Content-Transfer-Encoding: 7bit diff --git a/src/network/lookup_ipliteral.c b/src/network/lookup_ipliteral.c index 7bcb85f..209dc55 100644 --- a/src/network/lookup_ipliteral.c +++ b/src/network/lookup_ipliteral.c @@ -15,38 +15,43 @@ int __lookup_ipliteral(struct address buf[static 1], const char *name, int famil { struct in_addr a4; struct in6_addr a6; - if (family != AF_INET6 && __inet_aton(name, &a4)>0) { + if (__inet_aton(name, &a4) > 0) { + if (family == AF_INET6) /* wrong family */ + return EAI_NONAME; memcpy(&buf[0].addr, &a4, sizeof a4); buf[0].family = AF_INET; buf[0].scopeid = 0; return 1; } - if (family != AF_INET) { - char tmp[64]; - char *p = strchr(name, '%'), *z; - unsigned long long scopeid; - if (p && p-name < 64) { - memcpy(tmp, name, p-name); - tmp[p-name] = 0; - name = tmp; - } - if (inet_pton(AF_INET6, name, &a6)<=0) return 0; - memcpy(&buf[0].addr, &a6, sizeof a6); - buf[0].family = AF_INET6; - if (p) { - if (isdigit(*++p)) scopeid = strtoull(p, &z, 10); - else z = p-1; - if (*z) { - if (!IN6_IS_ADDR_LINKLOCAL(&a6) && - !IN6_IS_ADDR_MC_LINKLOCAL(&a6)) - return EAI_NONAME; - scopeid = if_nametoindex(p); - if (!scopeid) return EAI_NONAME; - } - if (scopeid > UINT_MAX) return EAI_NONAME; - buf[0].scopeid = scopeid; + + char tmp[64]; + char *p = strchr(name, '%'), *z; + unsigned long long scopeid; + if (p && p-name < 64) { + memcpy(tmp, name, p-name); + tmp[p-name] = 0; + name = tmp; + } + + if (inet_pton(AF_INET6, name, &a6) <= 0) + return 0; + if (family == AF_INET) /* wrong family */ + return EAI_NONAME; + + memcpy(&buf[0].addr, &a6, sizeof a6); + buf[0].family = AF_INET6; + if (p) { + if (isdigit(*++p)) scopeid = strtoull(p, &z, 10); + else z = p-1; + if (*z) { + if (!IN6_IS_ADDR_LINKLOCAL(&a6) && + !IN6_IS_ADDR_MC_LINKLOCAL(&a6)) + return EAI_NONAME; + scopeid = if_nametoindex(p); + if (!scopeid) return EAI_NONAME; } - return 1; + if (scopeid > UINT_MAX) return EAI_NONAME; + buf[0].scopeid = scopeid; } - return 0; + return 1; } --Apple-Mail=_87DFA2CB-04EC-4DA6-8576-E815B15637D1 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

=E2=80=94
Julien
= --Apple-Mail=_87DFA2CB-04EC-4DA6-8576-E815B15637D1-- --Apple-Mail=_4DFE8D35-A3AF-42DA-8D08-E9D57FBDCA3F-- From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8559 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: getaddrinfo usage with wrong ip family Date: Thu, 24 Sep 2015 12:59:01 +0200 Message-ID: <20150924105901.GI10551@port70.net> References: <06898546-AC9C-40F0-A2F5-2F1CC02E185C@gmail.com> <20150922151625.GX17773@brightrain.aerifal.cx> <71B72D33-A1D4-4B23-BFEB-6BFA01DF7523@gmail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1443092359 10765 80.91.229.3 (24 Sep 2015 10:59:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 24 Sep 2015 10:59:19 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-8571-gllmg-musl=m.gmane.org@lists.openwall.com Thu Sep 24 12:59:19 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 1Zf4FA-0005cD-Rf for gllmg-musl@m.gmane.org; Thu, 24 Sep 2015 12:59:17 +0200 Original-Received: (qmail 13457 invoked by uid 550); 24 Sep 2015 10:59:13 -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 13424 invoked from network); 24 Sep 2015 10:59:12 -0000 Mail-Followup-To: musl@lists.openwall.com Content-Disposition: inline In-Reply-To: <71B72D33-A1D4-4B23-BFEB-6BFA01DF7523@gmail.com> User-Agent: Mutt/1.5.23 (2014-03-12) Xref: news.gmane.org gmane.linux.lib.musl.general:8559 Archived-At: * Julien Ramseier [2015-09-24 12:27:22 +0200]: > > Le 22 sept. 2015 =E0 17:16, Rich Felker a =E9crit : > >=20 > > Another approach might be having __lookup_numeric always parse with > > AF_UNSPEC, but return error rather than 0 results if the resulting > > family does not match the requested family. >=20 > This seems the simplest solution in the meantime. >=20 > Here???s the patch I applied to my trunk. >=20 forgot to attach the patch? From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8562 Path: news.gmane.org!not-for-mail From: Julien Ramseier Newsgroups: gmane.linux.lib.musl.general Subject: Re: getaddrinfo usage with wrong ip family Date: Thu, 24 Sep 2015 17:11:03 +0200 Message-ID: <418CD580-74BC-4B3E-BA64-CB3AEA305843@gmail.com> References: <06898546-AC9C-40F0-A2F5-2F1CC02E185C@gmail.com> <20150922151625.GX17773@brightrain.aerifal.cx> <71B72D33-A1D4-4B23-BFEB-6BFA01DF7523@gmail.com> <20150924105901.GI10551@port70.net> 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: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1443107583 5051 80.91.229.3 (24 Sep 2015 15:13:03 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 24 Sep 2015 15:13:03 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-8574-gllmg-musl=m.gmane.org@lists.openwall.com Thu Sep 24 17:13:03 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 1Zf8B6-0005nF-Be for gllmg-musl@m.gmane.org; Thu, 24 Sep 2015 17:11:20 +0200 Original-Received: (qmail 30437 invoked by uid 550); 24 Sep 2015 15:11:18 -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 30407 invoked from network); 24 Sep 2015 15:11:17 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to; bh=Q2NSdQ6Ywa2So6NrTlILT8NHlGtAjAQJWHvdzSyevJk=; b=Jer2VxRWy4JM6wwuqbTV25fqnn7Pe26d7h6EPwRTQdC7ffPxA9oabBX/9tcaSKNV3m 5tARfOOT3NZ6Y/qecNfVcO7ZyraPiXsnmcRcyE/Q6WI5lTvERiM6Il9nSKIjztWAKvg9 BNYakhM12MayCg7ttYg764zaeTvybYw8eWUhVjejW4Z/8flFENscPyd+cNL4s7nTl/Ui a3rjhVlKZplNtTM9hqWYj01vKGuATwSjwan3ymffvGZubRRb5SSc1k4NCZOFfv+JmCFu QoPQ3gESLq8i7enTIKJJKwTXxfns6KxE/GbbW+oZ3iw+X7sV98CZs6x5TIhA31wsYTmE 8LYQ== X-Received: by 10.194.87.129 with SMTP id ay1mr234083wjb.110.1443107466173; Thu, 24 Sep 2015 08:11:06 -0700 (PDT) In-Reply-To: <20150924105901.GI10551@port70.net> X-Mailer: Apple Mail (2.2102) Xref: news.gmane.org gmane.linux.lib.musl.general:8562 Archived-At: > Le 24 sept. 2015 =E0 12:59, Szabolcs Nagy a =E9crit : >=20 > * Julien Ramseier [2015-09-24 12:27:22 +0200]: >>> Le 22 sept. 2015 =E0 17:16, Rich Felker a =E9crit = : >>>=20 >>> Another approach might be having __lookup_numeric always parse with >>> AF_UNSPEC, but return error rather than 0 results if the resulting >>> family does not match the requested family. >>=20 >> This seems the simplest solution in the meantime. >>=20 >> Here???s the patch I applied to my trunk. >>=20 >=20 > forgot to attach the patch? No, but maybe my mail client screwed it up. --- diff --git a/src/network/lookup_ipliteral.c = b/src/network/lookup_ipliteral.c index 7bcb85f..209dc55 100644 --- a/src/network/lookup_ipliteral.c +++ b/src/network/lookup_ipliteral.c @@ -15,38 +15,43 @@ int __lookup_ipliteral(struct address buf[static 1], = const char *name, int famil { struct in_addr a4; struct in6_addr a6; - if (family !=3D AF_INET6 && __inet_aton(name, &a4)>0) { + if (__inet_aton(name, &a4) > 0) { + if (family =3D=3D AF_INET6) /* wrong family */ + return EAI_NONAME; memcpy(&buf[0].addr, &a4, sizeof a4); buf[0].family =3D AF_INET; buf[0].scopeid =3D 0; return 1; } - if (family !=3D AF_INET) { - char tmp[64]; - char *p =3D strchr(name, '%'), *z; - unsigned long long scopeid; - if (p && p-name < 64) { - memcpy(tmp, name, p-name); - tmp[p-name] =3D 0; - name =3D tmp; - } - if (inet_pton(AF_INET6, name, &a6)<=3D0) return 0; - memcpy(&buf[0].addr, &a6, sizeof a6); - buf[0].family =3D AF_INET6; - if (p) { - if (isdigit(*++p)) scopeid =3D strtoull(p, &z, = 10); - else z =3D p-1; - if (*z) { - if (!IN6_IS_ADDR_LINKLOCAL(&a6) && - !IN6_IS_ADDR_MC_LINKLOCAL(&a6)) - return EAI_NONAME; - scopeid =3D if_nametoindex(p); - if (!scopeid) return EAI_NONAME; - } - if (scopeid > UINT_MAX) return EAI_NONAME; - buf[0].scopeid =3D scopeid; + + char tmp[64]; + char *p =3D strchr(name, '%'), *z; + unsigned long long scopeid; + if (p && p-name < 64) { + memcpy(tmp, name, p-name); + tmp[p-name] =3D 0; + name =3D tmp; + } + + if (inet_pton(AF_INET6, name, &a6) <=3D 0) + return 0; + if (family =3D=3D AF_INET) /* wrong family */ + return EAI_NONAME; + + memcpy(&buf[0].addr, &a6, sizeof a6); + buf[0].family =3D AF_INET6; + if (p) { + if (isdigit(*++p)) scopeid =3D strtoull(p, &z, 10); + else z =3D p-1; + if (*z) { + if (!IN6_IS_ADDR_LINKLOCAL(&a6) && + !IN6_IS_ADDR_MC_LINKLOCAL(&a6)) + return EAI_NONAME; + scopeid =3D if_nametoindex(p); + if (!scopeid) return EAI_NONAME; } - return 1; + if (scopeid > UINT_MAX) return EAI_NONAME; + buf[0].scopeid =3D scopeid; } - return 0; + return 1; } From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8564 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: getaddrinfo usage with wrong ip family Date: Thu, 24 Sep 2015 11:39:04 -0400 Message-ID: <20150924153904.GK17773@brightrain.aerifal.cx> References: <06898546-AC9C-40F0-A2F5-2F1CC02E185C@gmail.com> <20150922151625.GX17773@brightrain.aerifal.cx> <71B72D33-A1D4-4B23-BFEB-6BFA01DF7523@gmail.com> <20150924105901.GI10551@port70.net> <418CD580-74BC-4B3E-BA64-CB3AEA305843@gmail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1443109165 1778 80.91.229.3 (24 Sep 2015 15:39:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 24 Sep 2015 15:39:25 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-8576-gllmg-musl=m.gmane.org@lists.openwall.com Thu Sep 24 17:39:25 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 1Zf8cE-0002G0-AY for gllmg-musl@m.gmane.org; Thu, 24 Sep 2015 17:39:22 +0200 Original-Received: (qmail 24184 invoked by uid 550); 24 Sep 2015 15:39:19 -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 24156 invoked from network); 24 Sep 2015 15:39:18 -0000 Content-Disposition: inline In-Reply-To: <418CD580-74BC-4B3E-BA64-CB3AEA305843@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:8564 Archived-At: On Thu, Sep 24, 2015 at 05:11:03PM +0200, Julien Ramseier wrote: > > > Le 24 sept. 2015 à 12:59, Szabolcs Nagy a écrit : > > > > * Julien Ramseier [2015-09-24 12:27:22 +0200]: > >>> Le 22 sept. 2015 à 17:16, Rich Felker a écrit : > >>> > >>> Another approach might be having __lookup_numeric always parse with > >>> AF_UNSPEC, but return error rather than 0 results if the resulting > >>> family does not match the requested family. > >> > >> This seems the simplest solution in the meantime. > >> > >> Here???s the patch I applied to my trunk. > >> > > > > forgot to attach the patch? > > No, but maybe my mail client screwed it up. It was there, just deeply embedded in multiple layers of MIME. Rich From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8566 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: getaddrinfo usage with wrong ip family Date: Thu, 24 Sep 2015 21:48:56 -0400 Message-ID: <20150925014856.GM17773@brightrain.aerifal.cx> References: <06898546-AC9C-40F0-A2F5-2F1CC02E185C@gmail.com> <20150922151625.GX17773@brightrain.aerifal.cx> <71B72D33-A1D4-4B23-BFEB-6BFA01DF7523@gmail.com> <20150924105901.GI10551@port70.net> <418CD580-74BC-4B3E-BA64-CB3AEA305843@gmail.com> <20150924153904.GK17773@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1443145754 13987 80.91.229.3 (25 Sep 2015 01:49:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 25 Sep 2015 01:49:14 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-8578-gllmg-musl=m.gmane.org@lists.openwall.com Fri Sep 25 03:49:14 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 1ZfI8O-0002Be-9b for gllmg-musl@m.gmane.org; Fri, 25 Sep 2015 03:49:12 +0200 Original-Received: (qmail 4056 invoked by uid 550); 25 Sep 2015 01:49:09 -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 4031 invoked from network); 25 Sep 2015 01:49:08 -0000 Content-Disposition: inline In-Reply-To: <20150924153904.GK17773@brightrain.aerifal.cx> User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:8566 Archived-At: On Thu, Sep 24, 2015 at 11:39:04AM -0400, Rich Felker wrote: > On Thu, Sep 24, 2015 at 05:11:03PM +0200, Julien Ramseier wrote: > > > > > Le 24 sept. 2015 à 12:59, Szabolcs Nagy a écrit : > > > > > > * Julien Ramseier [2015-09-24 12:27:22 +0200]: > > >>> Le 22 sept. 2015 à 17:16, Rich Felker a écrit : > > >>> > > >>> Another approach might be having __lookup_numeric always parse with > > >>> AF_UNSPEC, but return error rather than 0 results if the resulting > > >>> family does not match the requested family. > > >> > > >> This seems the simplest solution in the meantime. > > >> > > >> Here???s the patch I applied to my trunk. > > >> > > > > > > forgot to attach the patch? > > > > No, but maybe my mail client screwed it up. > > It was there, just deeply embedded in multiple layers of MIME. The patch conflicted with commit cb1c88d42b0ee5e950d85e933c6eb6ecb8175e1d, but I've adapted and applied it. Let me know if you see anything I did wrong. Rich