From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CA3523858D37; Tue, 26 Apr 2022 08:30:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CA3523858D37 From: "kamilcukrowski at gmail dot com" To: glibc-bugs@sourceware.org Subject: [Bug locale/29090] New: strfmon does not set E2BIG when buffer is too small Date: Tue, 26 Apr 2022 08:30:57 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: locale X-Bugzilla-Version: 2.35 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: kamilcukrowski at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: glibc-bugs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-bugs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Apr 2022 08:30:57 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D29090 Bug ID: 29090 Summary: strfmon does not set E2BIG when buffer is too small Product: glibc Version: 2.35 Status: UNCONFIRMED Severity: normal Priority: P2 Component: locale Assignee: unassigned at sourceware dot org Reporter: kamilcukrowski at gmail dot com Target Milestone: --- > The glibc version you are using Arch Linux x86_64-pc-linux-gnu Linux leonidas 5.17.1-zen1-1-zen #1 ZEN SMP PREEMPT Mon, 28 Mar 2022 21:56:= 46 +0000 x86_64 GNU/Linu ldd (GNU libc) 2.35 gcc (GCC) 11.2.0 LC_ALL=3DC https://github.com/archlinux/svntogit-packages/blob/packages/glibc/trunk/PK= GBUILD#L63 > A description of the problem and some way to replicate the problem ``` #include #include #include #include int main() { char s[100]; ssize_t err =3D strfmon (s, 100, "%n", 123.45); printf("ret=3D%zd errno=3D%d,%s\n", err, errno, strerror(errno)); err =3D strfmon (s, 3, "%n", 123.45); printf("ret=3D%zd errno=3D%d,%s\n", err, errno, strerror(errno)); } ``` Just compiled with no options, results in: ``` ret=3D6 errno=3D0,Success ret=3D-1 errno=3D0,Success ``` > If your bug relates to incorrect behaviour of standardised interfaces, a = link to the appropriate section of the standard.=20 In the second call to `strfmon`, the `maxsize=3D3` so there is not enough s= pace for `123.45` 6+1 character string. So errno should be set to `E2BIG`. References https://pubs.opengroup.org/onlinepubs/9699919799/functions/strfmon.html: ``` Otherwise, -1 shall be returned, the contents of the array are unspecified,= and errno *shall* be set to indicate the error. ``` and references https://man7.org/linux/man-pages/man3/strfmon.3.html : ``` Otherwise, it sets errno to E2BIG, returns -1, and the contents of the arra= y is undefined. ``` Yet errno is not set, it's `0`. I think this is a bug, it should be set to E2BIG. > Any analysis of the problem you have performed.=20 The only place to `return -1` without setting `E2BIG` is from __printf_fp_l here https://github.com/bminor/glibc/blob/master/stdlib/strfmon_l.c#L547 : ``` done =3D __printf_fp_l (&f._sbf._f, loc, &info, &ptr); if (done < 0) return -1; ``` I tried to debug it and from the assembly as I undestand it I see that `__printf_fp_l` returns `-1`. And `__printf_fp_l` will return `-1` in case = of `_IO_*put*` return `EOF` https://github.com/bminor/glibc/blob/master/stdio-common/printf_fp.c#L78 an= d in this case it does not set errno. As I see it, all other `return -1` paths f= rom `__printf_fp_l` either come from `malloc -> NULL` or from `ERANGE`, and the ones that do not set errno come from `_IO_put/pad` calls. `_IO_str_jumps` f= rom https://github.com/bminor/glibc/blob/master/libio/strops.c also do not set errno. Thank you. --=20 You are receiving this mail because: You are on the CC list for the bug.=