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