From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by inbox.vuxu.org (Postfix) with SMTP id 3E47626A59 for ; Sat, 27 Jan 2024 17:21:12 +0100 (CET) Received: (qmail 1956 invoked by uid 550); 27 Jan 2024 16:18:54 -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 28053 invoked from network); 27 Jan 2024 15:01:32 -0000 Message-ID: <2ee42b57d19761973d1bd12e529a97cc00d829f3.camel@gentoo.org> From: =?UTF-8?Q?Micha=C5=82_G=C3=B3rny?= To: musl@lists.openwall.com Date: Sat, 27 Jan 2024 16:03:32 +0100 Organization: Gentoo Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-81EFZA1wgbLOw7i/o8QP" User-Agent: Evolution 3.50.3 MIME-Version: 1.0 Subject: [musl] [Bug?] getaddrinfo() fills .ai_canonname when AI_CANONNAME isn't passed --=-81EFZA1wgbLOw7i/o8QP Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello, While debugging a test suite failure in dnspython [1], we've discovered that the musl implementation of getaddrinfo() fills .ai_canonname field even if flags do not include AI_CANONNAME. We think that this could incorrect. Per POSIX: > If nodename is not null, and if requested by the AI_CANONNAME flag, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > the ai_canonname field of the first returned addrinfo structure shall > point to a null-terminated string containing the canonical name > corresponding to the input nodename; [...] > > All fields in socket address structures returned by getaddrinfo() that > are not filled in through an explicit argument (for example, > sin6_flowinfo) shall be set to zero. [2] I think the correct behavior would be to set the field to zero (i.e. null) when AI_CANONNAME is not present in flags. I've reproduced the problem on Gentoo Linux amd64 with musl 1.2.4, using the following test program: ``` #include #include #include #include int main(void) { struct addrinfo hints =3D {0}; struct addrinfo *res; struct addrinfo *p; hints.ai_family =3D AF_UNSPEC; hints.ai_socktype =3D SOCK_STREAM; hints.ai_flags =3D 0; if (getaddrinfo("example.com", NULL, &hints, &res) =3D=3D 0) { printf("%s\n", res->ai_canonname ? res->ai_canonname : "(null)"); freeaddrinfo(res); } return 0; } ``` On glibc system, it produces "(null)". On musl system, it produces "example.com". [1] https://github.com/rthalley/dnspython/issues/1035 [2] https://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.= html --=20 Best regards, Micha=C5=82 G=C3=B3rny --=-81EFZA1wgbLOw7i/o8QP Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- iQFGBAABCgAwFiEEx2qEUJQJjSjMiybFY5ra4jKeJA4FAmW1G0QSHG1nb3JueUBn ZW50b28ub3JnAAoJEGOa2uIyniQOmRkH/2z3jbCYr+x0NxgMoj0oLhAUqEep2Ojw cmX8AdE7BkefZZSd3/H4lYgMzlvxrvAXof+W4Nus/qRUHIMm2lGa4UJld6rUjjlf oQZ0/xegVCmKDCwzla8jM4iWLBMFOd3XI7JCk7p4UCQS3tEdlIhIQFX7x6aRPPhW VWUouF3VMKwVndiaEDisWOl3jSzo27BIAbk09T3P392mo4hloeFgfSy/xgOY30pW uUqnaCTVKYeRXlcKXSQK+MC6QgQzBGnZoXUSKnOronDIGJ0wr/g4RnCPKFimrtPA yfsx7uk4mgYHZVEu2ya5KMhPGiJNFN7RZ09FHUZn2WSVv1L/wqUdVns= =xeds -----END PGP SIGNATURE----- --=-81EFZA1wgbLOw7i/o8QP--