From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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.4 Received: (qmail 18901 invoked from network); 1 Nov 2020 20:48:47 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 1 Nov 2020 20:48:47 -0000 Received: (qmail 32301 invoked by uid 550); 1 Nov 2020 20:48:45 -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 32276 invoked from network); 1 Nov 2020 20:48:45 -0000 Date: Sun, 1 Nov 2020 21:48:32 +0100 From: Wolf To: musl@lists.openwall.com Message-ID: <20201101204832.zk7xmsdazrw7tz52@wolfsden.cz> References: <1597340845.300326000.m2kng81l@frv50.fwdcdn.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="q3svphq5d54srkun" Content-Disposition: inline In-Reply-To: Subject: Re: [musl] swprintf possible bug --q3svphq5d54srkun Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2020-11-01 17:17:49 -0300, =C3=89rico Nogueira wrote: > For what it's worth, if this is a bug, it would seem to be in how musl > decides when to print characters (not the formatting functions > themselves), since the below program doesn't print anything: >=20 > #include > #include >=20 > int main() { > fputws(L"[=D0=9F=D1=80=D0=B8=D0=B2=D0=B5=D1=82 =D0=92=D0=B0=D1=81=D0=B8= =D0=BB=D0=B8=D0=B9]\n", stdout); > // I don't know if I'm accessing a wchar_t appropriately here > fputwc(L"[=D0=9F=D1=80=D0=B8=D0=B2=D0=B5=D1=82 =D0=92=D0=B0=D1=81=D0=B8= =D0=BB=D0=B8=D0=B9]\n"[3], stdout); > return 0; > } >=20 > I tried tracing the execution from fputws, and not printing anything > seems to be caused by the return value of wcsrtombs(). That seems to be on the right track, since when you actually check the return code from fputws: #include #include int main(void) { if (fputws(L"[=D0=9F=D1=80=D0=B8=D0=B2=D0=B5=D1=82 =D0=92=D0=B0=D1=81=D0= =B8=D0=BB=D0=B8=D0=B9]\n", stdout) =3D=3D -1) { perror("fputws"); } } you get this: # ./a fputws: Illegal byte sequence I think it is caused by C (or POSIX) locale being default on entry to main, so you need to actually activate the system locale by calling setlocale(LC_ALL, ""). Indeed, if you modify the program to: #include #include #include int main(void) { setlocale(LC_ALL, ""); if (fputws(L"[=D0=9F=D1=80=D0=B8=D0=B2=D0=B5=D1=82 =D0=92=D0=B0=D1=81=D0= =B8=D0=BB=D0=B8=D0=B9]\n", stdout) =3D=3D -1) { perror("fputws"); } } It starts to work: # ./a [=D0=9F=D1=80=D0=B8=D0=B2=D0=B5=D1=82 =D0=92=D0=B0=D1=81=D0=B8=D0=BB=D0=B8= =D0=B9] W. --=20 There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors. --q3svphq5d54srkun Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEE7BIrb0FxyZaks1p7hTP5S2N55TgFAl+fHyAACgkQhTP5S2N5 5Tj04A/9E55DKqXFiq6Ig+zM8Sn9X7fIPLQqVpAlmITnxOmFHrnss3hY9bLBf5ZJ Sn0Lj39UjqrCyRkOmJoo1DDIa8Knuoei6lRyyERYwrn9kf11QpTJyR0YhAwHRUNL fJt3ZSbmPY26M3+pzmz6zVcj5gqsdyDvUyGQgclcHkbdyWpLdbC8fY1U2DueXXN+ zXFTafQTRUBCSxGWHUkEdohrIac2rJde3Xuj3M4AES0hUynlXbocPInVNnrFxcyi HuzfOV8SETn9BPEYFY5d3fcNW6PbVdA1NKRQbqF+peaw5acl2T3ZnYDJwz4QYtW2 IDSawOVAY0b0hhv5QthwpNubUw8KptZMfhISy+IKWEu1RVVDoke9jDgpDRlyfiNk IDkbKQjA+GbX7xYyotFyFhCUjkgSGhbM/Y6Cmx6mzLQoDeQPtmDvZ68OMQ/c6CnR 9wKhQGwDQTWyaUFKNtbqc/Iq0Ozs1JlvFKiREsBR+x2ZDzbzRHDJ8+dPEIih9Ouj lxfoWWO3ziYklKOv8GU+WAx8So4jF7pZxsAsF77QHpINqv88VNsymxjzYL2LClTC rse6suuq1Mb156GHqgAHveVfnQNsCf2dMyoAoWVVo40b3CthuCZJnQosTmLxrFOf sBRf9aaQ3LY9Dg8hMlrURz1+doRxQYx0mME3i6+rTlDi49dB2Nk= =hVDo -----END PGP SIGNATURE----- --q3svphq5d54srkun--