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; }