From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=5.0 tests=DKIM_ADSP_ALL, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.2 Received: (qmail 20142 invoked from network); 26 Apr 2020 00:15:44 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with UTF8ESMTPZ; 26 Apr 2020 00:15:44 -0000 Received: (qmail 24568 invoked by uid 550); 26 Apr 2020 00:15:38 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 24547 invoked from network); 26 Apr 2020 00:15:37 -0000 Date: Sun, 26 Apr 2020 02:15:22 +0200 From: Wolf To: musl@lists.openwall.com Message-ID: <20200426001522.rgwtcn66zquyrufq@wolfsden.cz> References: <20200313214648.2qqr5utzyqy5ewsu@wolfsden.cz> <20200417184222.GL11469@brightrain.aerifal.cx> <20200417184640.GM11469@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="vyovxcqhzgf35a6b" Content-Disposition: inline In-Reply-To: <20200417184640.GM11469@brightrain.aerifal.cx> Subject: Re: [musl] Proposal to match behaviour of gethostbyname to glibc --vyovxcqhzgf35a6b Content-Type: multipart/mixed; boundary="iq5dxtsbb7u3oafa" Content-Disposition: inline --iq5dxtsbb7u3oafa Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello, On 2020-04-17 14:46:40 -0400, Rich Felker wrote: > Actually now that I'm doing this I'm not sure it's correct. The > existing code reports all matches from the hosts file, not just the > first one. This patch will prevent getting both ipv4 and ipv6 results, > or multiple results for the same address family, by stopping after the > first one. Well, I've completely missed that. Sorry. > If you want the canonical name to come from the first result, rather > than suppressing all but the first result, the code instead needs to > be changed to remember that it already found one name and not copy any > others. I've attached patch v2 doing exactly that. Hopefully this time it's correct. W. --=20 There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors. --iq5dxtsbb7u3oafa Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=patch Content-Transfer-Encoding: quoted-printable diff --git a/src/network/lookup_name.c b/src/network/lookup_name.c index c93263a9..00f056e6 100644 --- a/src/network/lookup_name.c +++ b/src/network/lookup_name.c @@ -50,7 +50,7 @@ static int name_from_hosts(struct address buf[static MAXA= DDRS], char canon[stati { char line[512]; size_t l =3D strlen(name); - int cnt =3D 0, badfam =3D 0; + int cnt =3D 0, badfam =3D 0, have_canon =3D 0; unsigned char _buf[1032]; FILE _f, *f =3D __fopen_rb_ca("/etc/hosts", &_f, _buf, sizeof _buf); if (!f) switch (errno) { @@ -83,11 +83,16 @@ static int name_from_hosts(struct address buf[static MA= XADDRS], char canon[stati continue; } =20 + if (have_canon) continue; + /* Extract first name as canonical name */ for (; *p && isspace(*p); p++); for (z=3Dp; *z && !isspace(*z); z++); *z =3D 0; - if (is_valid_hostname(p)) memcpy(canon, p, z-p+1); + if (is_valid_hostname(p)) { + have_canon =3D 1; + memcpy(canon, p, z-p+1); + } } __fclose_ca(f); return cnt ? cnt : badfam; --iq5dxtsbb7u3oafa-- --vyovxcqhzgf35a6b Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEE7BIrb0FxyZaks1p7hTP5S2N55TgFAl6k0poACgkQhTP5S2N5 5TgRDw//UWQ47j+jP3zaTV7YkrwJizOEZfUJ5/AYvCRqf4yWg1vCa7poM3Y68VZU xkSk8uuUatZPsIftwriuAi5YofoQrEi0gwyV6uqKM7UxipaEk3kcsXIlkCj86i6A MmOPilYGpm4Rjc5qc881j2gAFn19hUaQbJK/W4pBYN8gDzDWDKxCDlNRc5i8LHjC 5V3sf3DLvF8n/NZLNZaT5OXZjNV9W90QolQyB+axy+CQccLitbTcTjK/D30LAia/ ui5oDRN8eQu7jwrON59rHj6QlbnBLUg1J+vj4zgkKXwGePdvGcr0S//vVX+yN22c 9pwuwWRJfcX9YeQy6GiXB8rc3v2EGoSJ0oPlLOUEL8B9ishckIMKZ/6t6srdQrdH Y9jzPl1ihpZVD8OG6WwG6l6myuE4n8PbJ96YIV9rcwtZCL/psSmDAiGEBp0Wpp9A 4SkE2up6MWjkKc32rh/2XJOXH4B3KrAjf12vL3JD89pPUi8mk7wvrhBssE8bfsrr o9H4OM2IlJLzwgeHyKE1qoqLP/Lr0YE3qBN+p6CjNzRa+JoYeQSyrcVWcFDdBZ4f 4ln4DqJ0XM5pf4kcgHTU/sycfKAc+CpiZRYoGzHHgBlx/PYrCufTU4p5Py+aP01p pFCt63/Q43KCcg9oT7HDf6vqCpeQtf74R96JZUyHS3hz7BxpzII= =abYx -----END PGP SIGNATURE----- --vyovxcqhzgf35a6b--