public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/30371] New: C2x strtol binary constant handling is incomplete
@ 2023-04-18 17:44 bruno at clisp dot org
  2023-04-18 19:42 ` [Bug libc/30371] " kdudka at redhat dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: bruno at clisp dot org @ 2023-04-18 17:44 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=30371

            Bug ID: 30371
           Summary: C2x strtol binary constant handling is incomplete
           Product: glibc
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: bruno at clisp dot org
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

Created attachment 14838
  --> https://sourceware.org/bugzilla/attachment.cgi?id=14838&action=edit
proposed fix

In the functions strtol/strtoul/strtoll/strtoull, support for binary
constants (such as 0b100111), as specified in ISO C 2x, was added
in glibc commit 64924422a99690d147a166b4de3103f3bf3eaf6c, on 2023-02-17.

But it is incomplete: The special input string "0b" with no binary digits
is not handled.

Here's a test case:
==================== tst-strtol-binary-no-digits.c ====================
#include <assert.h>
#include <errno.h>
#include <stdlib.h>

int main ()
{
  {
    const char input[] = "0b";
    char *ptr;
    long result;
    errno = 0;
    result = strtol (input, &ptr, 2);
    assert (result == 0L);
    assert (ptr == input + 1);
    assert (errno == 0);
  }
  {
    const char input[] = "0b";
    char *ptr;
    long result;
    errno = 0;
    result = strtol (input, &ptr, 0);
    assert (result == 0L);
    assert (ptr == input + 1);
    assert (errno == 0);
  }
}
=======================================================================

Find attached a correction for this. I have tested it in Gnulib (which
has very similar source code as glibc for this functionality), not in
Glibc directly.

I previously reported this to libc-alpha at
https://sourceware.org/pipermail/libc-alpha/2023-March/146367.html
but I now realize that this was not the proper reporting channel.
Sorry about that.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libc/30371] C2x strtol binary constant handling is incomplete
  2023-04-18 17:44 [Bug libc/30371] New: C2x strtol binary constant handling is incomplete bruno at clisp dot org
@ 2023-04-18 19:42 ` kdudka at redhat dot com
  2023-04-18 21:08 ` eblake at redhat dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: kdudka at redhat dot com @ 2023-04-18 19:42 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=30371

Kamil Dudka <kdudka at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kdudka at redhat dot com

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libc/30371] C2x strtol binary constant handling is incomplete
  2023-04-18 17:44 [Bug libc/30371] New: C2x strtol binary constant handling is incomplete bruno at clisp dot org
  2023-04-18 19:42 ` [Bug libc/30371] " kdudka at redhat dot com
@ 2023-04-18 21:08 ` eblake at redhat dot com
  2023-04-18 21:13 ` eblake at redhat dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: eblake at redhat dot com @ 2023-04-18 21:08 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=30371

Eric Blake <eblake at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eblake at redhat dot com

--- Comment #1 from Eric Blake <eblake at redhat dot com> ---
Note that C2X has not yet decided what to do about strto*l parsing with a
binary prefix.  Consider:

strtoul("0b1", &end, 2);

In C17, this is required to return 0 and set end to "b1"; if C2X adds binary
parsing, it would be required to return 1 and set end to "".  This is a SILENT
change in runtime behavior, based on which version of the standard you build
against.

https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3072.htm#there-are-semantic-changes-and-inconsistencies-for-strtol-scanf-and-similar-functions

The final version of C2X may state something different than in the draft, and
glibc may have to course-correct yet again.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libc/30371] C2x strtol binary constant handling is incomplete
  2023-04-18 17:44 [Bug libc/30371] New: C2x strtol binary constant handling is incomplete bruno at clisp dot org
  2023-04-18 19:42 ` [Bug libc/30371] " kdudka at redhat dot com
  2023-04-18 21:08 ` eblake at redhat dot com
@ 2023-04-18 21:13 ` eblake at redhat dot com
  2023-04-18 21:42 ` bruno at clisp dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: eblake at redhat dot com @ 2023-04-18 21:13 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=30371

--- Comment #2 from Eric Blake <eblake at redhat dot com> ---
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3108.doc merely says:

FR-228
7.24.1, 7.31.4.1, K.3.5.3 and K.3.9.1
te
There are semantic changes and inconsistencies for strtol, scanf and similar
functions
see accompanying document
Rejected (no consensus to make this change) with comment: several vendor
solutions were discussed.

so as recently as Feb 2023, the C working group still hasn't made up their
mind.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libc/30371] C2x strtol binary constant handling is incomplete
  2023-04-18 17:44 [Bug libc/30371] New: C2x strtol binary constant handling is incomplete bruno at clisp dot org
                   ` (2 preceding siblings ...)
  2023-04-18 21:13 ` eblake at redhat dot com
@ 2023-04-18 21:42 ` bruno at clisp dot org
  2023-04-19  2:46 ` sam at gentoo dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: bruno at clisp dot org @ 2023-04-18 21:42 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=30371

--- Comment #3 from Bruno Haible <bruno at clisp dot org> ---
(In reply to Eric Blake from comment #1)
> Note that C2X has not yet decided what to do about strto*l parsing with a
> binary prefix.  ... This is a
> SILENT change in runtime behavior, based on which version of the standard
> you build against.

Yes, but the fact that it's a change in runtime behaviour is handled by the
introduction of __isoc23_strto*, __isoc23_wcsto* in Joseph Myers' patch
https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=64924422a99690d147a166b4de3103f3bf3eaf6c
.

If "Rejected" (as in comment #2) means that the final ISO C 23 will have the
same wording as https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3088.pdf (the
latest draft from 2023-01-24), then the wording there (§ 7.24.1.7, page 358 =
377/757) means that when parsing the input string "0b", only one character
shall be consumed, like for the input string "0x". That is what this BZ and its
proposed patch are about.

> The final version of C2X may state something different than in the draft,
> and glibc may have to course-correct yet again.

True. But it's very unlikely that the final version of C2X will specify that in
when parsing "0b" two characters shall be consumed, while when parsing "0x"
only one character shall be consumed.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libc/30371] C2x strtol binary constant handling is incomplete
  2023-04-18 17:44 [Bug libc/30371] New: C2x strtol binary constant handling is incomplete bruno at clisp dot org
                   ` (3 preceding siblings ...)
  2023-04-18 21:42 ` bruno at clisp dot org
@ 2023-04-19  2:46 ` sam at gentoo dot org
  2023-04-20 14:58 ` mliska at suse dot cz
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: sam at gentoo dot org @ 2023-04-19  2:46 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=30371

Sam James <sam at gentoo dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sam at gentoo dot org

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libc/30371] C2x strtol binary constant handling is incomplete
  2023-04-18 17:44 [Bug libc/30371] New: C2x strtol binary constant handling is incomplete bruno at clisp dot org
                   ` (4 preceding siblings ...)
  2023-04-19  2:46 ` sam at gentoo dot org
@ 2023-04-20 14:58 ` mliska at suse dot cz
  2023-05-22 16:42 ` eggert at cs dot ucla.edu
  2023-07-03 20:14 ` bruno at clisp dot org
  7 siblings, 0 replies; 9+ messages in thread
From: mliska at suse dot cz @ 2023-04-20 14:58 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=30371

Martin Liska <mliska at suse dot cz> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mliska at suse dot cz

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libc/30371] C2x strtol binary constant handling is incomplete
  2023-04-18 17:44 [Bug libc/30371] New: C2x strtol binary constant handling is incomplete bruno at clisp dot org
                   ` (5 preceding siblings ...)
  2023-04-20 14:58 ` mliska at suse dot cz
@ 2023-05-22 16:42 ` eggert at cs dot ucla.edu
  2023-07-03 20:14 ` bruno at clisp dot org
  7 siblings, 0 replies; 9+ messages in thread
From: eggert at cs dot ucla.edu @ 2023-05-22 16:42 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=30371

eggert at cs dot ucla.edu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eggert at cs dot ucla.edu

--- Comment #4 from eggert at cs dot ucla.edu ---
I installed the following patch to Gnulib:

https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=3ad52f3e21db96096105256ff66ebf480703a09f

This should work around this glibc bug in applications that use Gnulib.
However, these applications will compile their own substitutes for strtol etc.
It'd be better to fix this in glibc.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libc/30371] C2x strtol binary constant handling is incomplete
  2023-04-18 17:44 [Bug libc/30371] New: C2x strtol binary constant handling is incomplete bruno at clisp dot org
                   ` (6 preceding siblings ...)
  2023-05-22 16:42 ` eggert at cs dot ucla.edu
@ 2023-07-03 20:14 ` bruno at clisp dot org
  7 siblings, 0 replies; 9+ messages in thread
From: bruno at clisp dot org @ 2023-07-03 20:14 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=30371

Bruno Haible <bruno at clisp dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #5 from Bruno Haible <bruno at clisp dot org> ---
Adhemerval Zanella committed my proposed fix into glibc on 2023-05-25.
The bug is thus fixed for glibc-2.38.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-07-03 20:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-18 17:44 [Bug libc/30371] New: C2x strtol binary constant handling is incomplete bruno at clisp dot org
2023-04-18 19:42 ` [Bug libc/30371] " kdudka at redhat dot com
2023-04-18 21:08 ` eblake at redhat dot com
2023-04-18 21:13 ` eblake at redhat dot com
2023-04-18 21:42 ` bruno at clisp dot org
2023-04-19  2:46 ` sam at gentoo dot org
2023-04-20 14:58 ` mliska at suse dot cz
2023-05-22 16:42 ` eggert at cs dot ucla.edu
2023-07-03 20:14 ` bruno at clisp dot org

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).