public inbox for glibc-bugs@sourceware.org help / color / mirror / Atom feed
From: "kamilcukrowski at gmail dot com" <sourceware-bugzilla@sourceware.org> 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 [thread overview] Message-ID: <bug-29090-131@http.sourceware.org/bugzilla/> (raw) https://sourceware.org/bugzilla/show_bug.cgi?id=29090 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=C https://github.com/archlinux/svntogit-packages/blob/packages/glibc/trunk/PKGBUILD#L63 > A description of the problem and some way to replicate the problem ``` #include <errno.h> #include <string.h> #include <stdio.h> #include <monetary.h> int main() { char s[100]; ssize_t err = strfmon (s, 100, "%n", 123.45); printf("ret=%zd errno=%d,%s\n", err, errno, strerror(errno)); err = strfmon (s, 3, "%n", 123.45); printf("ret=%zd errno=%d,%s\n", err, errno, strerror(errno)); } ``` Just compiled with no options, results in: ``` ret=6 errno=0,Success ret=-1 errno=0,Success ``` > If your bug relates to incorrect behaviour of standardised interfaces, a link to the appropriate section of the standard. In the second call to `strfmon`, the `maxsize=3` so there is not enough space 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 array 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. 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 = __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 and in this case it does not set errno. As I see it, all other `return -1` paths from `__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` from https://github.com/bminor/glibc/blob/master/libio/strops.c also do not set errno. Thank you. -- You are receiving this mail because: You are on the CC list for the bug.
next reply other threads:[~2022-04-26 8:30 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-04-26 8:30 kamilcukrowski at gmail dot com [this message] 2022-04-26 9:18 ` [Bug locale/29090] " fweimer at redhat dot com 2023-04-13 14:21 ` schwab@linux-m68k.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-29090-131@http.sourceware.org/bugzilla/ \ --to=sourceware-bugzilla@sourceware.org \ --cc=glibc-bugs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).