public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug string/29265] New: mbstowcs with NULL dst throws an incorrect warning (glibc == 2.35, gcc=12.0.1)
@ 2022-06-20 14:01 goldstein.w.n at gmail dot com
  2022-06-21  2:37 ` [Bug string/29265] " siddhesh at sourceware dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: goldstein.w.n at gmail dot com @ 2022-06-20 14:01 UTC (permalink / raw)
  To: glibc-bugs

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

            Bug ID: 29265
           Summary: mbstowcs with NULL dst throws an incorrect warning
                    (glibc == 2.35, gcc=12.0.1)
           Product: glibc
           Version: 2.35
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: string
          Assignee: unassigned at sourceware dot org
          Reporter: goldstein.w.n at gmail dot com
  Target Milestone: ---

For example building binutils HEAD get the following warning:

```
In file included from /usr/include/features.h:486,
                 from
/usr/include/x86_64-linux-gnu/bits/libc-header-start.h:33,
                 from /usr/include/stdio.h:27,
                 from as.h:42,
                 from read.c:33:
In function ‘mbstowcs’,
    inlined from ‘read_symbol_name’ at read.c:1670:11:
/usr/include/x86_64-linux-gnu/bits/stdlib.h:115:10: error: argument 1 is null
but the corresponding size argument 3 value is [128, 9223372036854775807]
[-Werror=nonnull]
  115 |   return __glibc_fortify_n (mbstowcs, __len, sizeof (wchar_t),
      |          ^~~~~~~~~~~~~~~~~
In file included from /usr/include/stdlib.h:1027,
                 from as.h:44:
/usr/include/x86_64-linux-gnu/bits/stdlib.h: In function ‘read_symbol_name’:
/usr/include/x86_64-linux-gnu/bits/stdlib.h:95:15: note: in a call to function
‘__mbstowcs_chk’ declared with attribute ‘access (read_only, 2)’
   95 | extern size_t __mbstowcs_chk (wchar_t *__restrict __dst,

```

Which is from:
https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=gas/read.c;h=c6ce0345892284a48e5280ebb9cca111fab975f4;hb=HEAD#l1670
```
1670:    if (mbstowcs (NULL, name, len) == (size_t) -1)
```

`mbstowcs` supports a NULL destination:
https://en.cppreference.com/w/cpp/string/multibyte/mbstowcs#:~:text=POSIX%20specifies%20a%20common%20extension%3A%20if%20dst%20is%20a%20null%20pointer%2C%20this%20function%20returns%20the%20number%20of%20wide%20characters%20that%20would%20be%20written%20to%20dst%2C%20if%20converted.%20Similar%20behavior%20is%20standard%20for%20std%3A%3Ambsrtowcs.

so that seems like a bug in the GLIBC attributes of `mbstowcs`.

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

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

* [Bug string/29265] mbstowcs with NULL dst throws an incorrect warning (glibc == 2.35, gcc=12.0.1)
  2022-06-20 14:01 [Bug string/29265] New: mbstowcs with NULL dst throws an incorrect warning (glibc == 2.35, gcc=12.0.1) goldstein.w.n at gmail dot com
@ 2022-06-21  2:37 ` siddhesh at sourceware dot org
  2022-06-21  2:44 ` goldstein.w.n at gmail dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: siddhesh at sourceware dot org @ 2022-06-21  2:37 UTC (permalink / raw)
  To: glibc-bugs

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

Siddhesh Poyarekar <siddhesh at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
                 CC|                            |siddhesh at sourceware dot org
   Last reconfirmed|                            |2022-06-21

--- Comment #1 from Siddhesh Poyarekar <siddhesh at sourceware dot org> ---
Agreed, the __attr_access ((__write_only__, 1, 3)) is incorrect for mbstowcs,
the former requires the size argument to accurately reflect the object argument
(i.e. 0 for a NULL pointer) whereas the mbstowcs implementation is expected to
ignore the size argument if the first argument is NULL.  Would you like to
write a patch to fix this up?

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

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

* [Bug string/29265] mbstowcs with NULL dst throws an incorrect warning (glibc == 2.35, gcc=12.0.1)
  2022-06-20 14:01 [Bug string/29265] New: mbstowcs with NULL dst throws an incorrect warning (glibc == 2.35, gcc=12.0.1) goldstein.w.n at gmail dot com
  2022-06-21  2:37 ` [Bug string/29265] " siddhesh at sourceware dot org
@ 2022-06-21  2:44 ` goldstein.w.n at gmail dot com
  2022-06-21  3:30 ` goldstein.w.n at gmail dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: goldstein.w.n at gmail dot com @ 2022-06-21  2:44 UTC (permalink / raw)
  To: glibc-bugs

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

--- Comment #2 from Noah Goldstein <goldstein.w.n at gmail dot com> ---
Sure(In reply to Siddhesh Poyarekar from comment #1)
> Agreed, the __attr_access ((__write_only__, 1, 3)) is incorrect for
> mbstowcs, the former requires the size argument to accurately reflect the
> object argument (i.e. 0 for a NULL pointer) whereas the mbstowcs
> implementation is expected to ignore the size argument if the first argument
> is NULL.  Would you like to write a patch to fix this up?


Sure.

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

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

* [Bug string/29265] mbstowcs with NULL dst throws an incorrect warning (glibc == 2.35, gcc=12.0.1)
  2022-06-20 14:01 [Bug string/29265] New: mbstowcs with NULL dst throws an incorrect warning (glibc == 2.35, gcc=12.0.1) goldstein.w.n at gmail dot com
  2022-06-21  2:37 ` [Bug string/29265] " siddhesh at sourceware dot org
  2022-06-21  2:44 ` goldstein.w.n at gmail dot com
@ 2022-06-21  3:30 ` goldstein.w.n at gmail dot com
  2022-06-21  3:46 ` siddhesh at sourceware dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: goldstein.w.n at gmail dot com @ 2022-06-21  3:30 UTC (permalink / raw)
  To: glibc-bugs

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

--- Comment #3 from Noah Goldstein <goldstein.w.n at gmail dot com> ---
Created attachment 14157
  --> https://sourceware.org/bugzilla/attachment.cgi?id=14157&action=edit
Potential Patch

Not able to reproduce the issue in glibc test suite so not fully confident in
this change.

Siddhesh, any ideas for how to get this error to throw in testmb.c?

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

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

* [Bug string/29265] mbstowcs with NULL dst throws an incorrect warning (glibc == 2.35, gcc=12.0.1)
  2022-06-20 14:01 [Bug string/29265] New: mbstowcs with NULL dst throws an incorrect warning (glibc == 2.35, gcc=12.0.1) goldstein.w.n at gmail dot com
                   ` (2 preceding siblings ...)
  2022-06-21  3:30 ` goldstein.w.n at gmail dot com
@ 2022-06-21  3:46 ` siddhesh at sourceware dot org
  2022-06-21  4:26 ` goldstein.w.n at gmail dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: siddhesh at sourceware dot org @ 2022-06-21  3:46 UTC (permalink / raw)
  To: glibc-bugs

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

--- Comment #4 from Siddhesh Poyarekar <siddhesh at sourceware dot org> ---
I'm not very picky about having a test for this FWIW, this seems very sensitive
to optimizations and may not survive gcc updates.

As for the fix, just remove the  __attr_access ((__write_only__, 1, 3)), it's
incorrect in the context of mbstowcs definition.

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

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

* [Bug string/29265] mbstowcs with NULL dst throws an incorrect warning (glibc == 2.35, gcc=12.0.1)
  2022-06-20 14:01 [Bug string/29265] New: mbstowcs with NULL dst throws an incorrect warning (glibc == 2.35, gcc=12.0.1) goldstein.w.n at gmail dot com
                   ` (3 preceding siblings ...)
  2022-06-21  3:46 ` siddhesh at sourceware dot org
@ 2022-06-21  4:26 ` goldstein.w.n at gmail dot com
  2022-06-21  4:45 ` siddhesh at sourceware dot org
  2022-08-06  9:16 ` vincent.vsmeets at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: goldstein.w.n at gmail dot com @ 2022-06-21  4:26 UTC (permalink / raw)
  To: glibc-bugs

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

--- Comment #5 from Noah Goldstein <goldstein.w.n at gmail dot com> ---
(In reply to Siddhesh Poyarekar from comment #4)
> I'm not very picky about having a test for this FWIW, this seems very
> sensitive to optimizations and may not survive gcc updates.
> 
> As for the fix, just remove the  __attr_access ((__write_only__, 1, 3)),
> it's incorrect in the context of mbstowcs definition.

You don't think its worth preserving if dst is non-null? In that case it is
meaningful no?

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

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

* [Bug string/29265] mbstowcs with NULL dst throws an incorrect warning (glibc == 2.35, gcc=12.0.1)
  2022-06-20 14:01 [Bug string/29265] New: mbstowcs with NULL dst throws an incorrect warning (glibc == 2.35, gcc=12.0.1) goldstein.w.n at gmail dot com
                   ` (4 preceding siblings ...)
  2022-06-21  4:26 ` goldstein.w.n at gmail dot com
@ 2022-06-21  4:45 ` siddhesh at sourceware dot org
  2022-08-06  9:16 ` vincent.vsmeets at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: siddhesh at sourceware dot org @ 2022-06-21  4:45 UTC (permalink / raw)
  To: glibc-bugs

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

--- Comment #6 from Siddhesh Poyarekar <siddhesh at sourceware dot org> ---
(In reply to Noah Goldstein from comment #5)
> (In reply to Siddhesh Poyarekar from comment #4)
> > I'm not very picky about having a test for this FWIW, this seems very
> > sensitive to optimizations and may not survive gcc updates.
> > 
> > As for the fix, just remove the  __attr_access ((__write_only__, 1, 3)),
> > it's incorrect in the context of mbstowcs definition.
> 
> You don't think its worth preserving if dst is non-null? In that case it is
> meaningful no?

It is meaningful, just that the check may trigger if the dest pointer has not
yet been simplified to a const.  Although, maybe I'm overthinking it.  Lets go
with what you have.

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

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

* [Bug string/29265] mbstowcs with NULL dst throws an incorrect warning (glibc == 2.35, gcc=12.0.1)
  2022-06-20 14:01 [Bug string/29265] New: mbstowcs with NULL dst throws an incorrect warning (glibc == 2.35, gcc=12.0.1) goldstein.w.n at gmail dot com
                   ` (5 preceding siblings ...)
  2022-06-21  4:45 ` siddhesh at sourceware dot org
@ 2022-08-06  9:16 ` vincent.vsmeets at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: vincent.vsmeets at gmail dot com @ 2022-08-06  9:16 UTC (permalink / raw)
  To: glibc-bugs

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

Vincent Smeets <vincent.vsmeets at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vincent.vsmeets at gmail dot com

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

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

end of thread, other threads:[~2022-08-06  9:16 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-20 14:01 [Bug string/29265] New: mbstowcs with NULL dst throws an incorrect warning (glibc == 2.35, gcc=12.0.1) goldstein.w.n at gmail dot com
2022-06-21  2:37 ` [Bug string/29265] " siddhesh at sourceware dot org
2022-06-21  2:44 ` goldstein.w.n at gmail dot com
2022-06-21  3:30 ` goldstein.w.n at gmail dot com
2022-06-21  3:46 ` siddhesh at sourceware dot org
2022-06-21  4:26 ` goldstein.w.n at gmail dot com
2022-06-21  4:45 ` siddhesh at sourceware dot org
2022-08-06  9:16 ` vincent.vsmeets at gmail dot com

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