From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 131D7384773A; Wed, 3 Apr 2024 08:14:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 131D7384773A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1712132056; bh=/WU//UqP4ncCEWNzWww/EhnHsWebt81R8sZf0Abykmc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=xp8WGPp9PiC+E1SFB8WMe7p68hRnBWt6TAPwoRht6NK14XJbem01KL/QEl+G2kal4 AxNICh7ssad7+DAFS6hribpoLY+jPqcC2sn/gnQkaF4Hy+Z2iusLdxTwHp1vjNzLaN GYDRjy6dYWTcyFdX4Ey/ewEHoDEMJLd5CMhZ1aJI= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libquadmath/114533] libquadmath: printf: fix misaligned access on args Date: Wed, 03 Apr 2024 08:14:14 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libquadmath X-Bugzilla-Version: 13.2.1 X-Bugzilla-Keywords: ABI X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: jakub at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114533 --- Comment #12 from GCC Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:8455d6f6cd43b7b143ab9ee19437452fceba9cc9 commit r14-9769-g8455d6f6cd43b7b143ab9ee19437452fceba9cc9 Author: Jakub Jelinek Date: Wed Apr 3 10:02:35 2024 +0200 libquadmath: Don't assume the storage for __float128 arguments is align= ed [PR114533] With the register_printf_type/register_printf_modifier/register_printf_specifier APIs the C library is just told the size of the argument and is provided with a callback to fetch the argument from va_list using va_arg into C libra= ry provided memory. The C library isn't told what alignment requirement it has, bu= t we were using direct load of a __float128 value from that memory which assumes __alignof (__float128) alignment. The following patch fixes that by using memcpy instead. I haven't been able to reproduce an actual crash, tried #include #include #include int main () { __float128 r; int prec =3D 20; int width =3D 46; char buf[128]; r =3D 2.0q; r =3D sqrtq (r); int n =3D quadmath_snprintf (buf, sizeof buf, "%+-#*.20Qe", width, r); if ((size_t) n < sizeof buf) printf ("%s\n", buf); /* Prints: +1.41421356237309504880e+00 */ quadmath_snprintf (buf, sizeof buf, "%Qa", r); if ((size_t) n < sizeof buf) printf ("%s\n", buf); /* Prints: 0x1.6a09e667f3bcc908b2fb1366ea96p+0 */ n =3D quadmath_snprintf (NULL, 0, "%+-#46.*Qe", prec, r); if (n > -1) { char *str =3D malloc (n + 1); if (str) { quadmath_snprintf (str, n + 1, "%+-#46.*Qe", prec, r); printf ("%s\n", str); /* Prints: +1.41421356237309504880e+00 */ } free (str); } printf ("%+-#*.20Qe\n", width, r); printf ("%Qa\n", r); printf ("%+-#46.*Qe\n", prec, r); printf ("%d %Qe %d %Qe %d %Qe\n", 1, r, 2, r, 3, r); return 0; } In any case, I think memcpy for loading from it is right. 2024-04-03 Simon Chopin Jakub Jelinek PR libquadmath/114533 * printf/printf_fp.c (__quadmath_printf_fp): Use memcpy to copy __float128 out of args. * printf/printf_fphex.c (__quadmath_printf_fphex): Likewise. Signed-off-by: Simon Chopin =