public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/105957] New: __n * sizeof(_Tp) might overflow under consteval context for std::allocator
@ 2022-06-13 19:10 unlvsur at live dot com
  2022-06-14  9:32 ` [Bug libstdc++/105957] " redi at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: unlvsur at live dot com @ 2022-06-13 19:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105957

            Bug ID: 105957
           Summary: __n * sizeof(_Tp) might overflow under consteval
                    context for std::allocator
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: unlvsur at live dot com
  Target Milestone: ---

https://github.com/gcc-mirror/gcc/blob/b3dd7d8b48227d3489039ca66b6c0ea2da743255/libstdc%2B%2B-v3/include/bits/allocator.h#L187

__n * sizeof(_Tp) can overflow under consteval context. Need checks i believe.
return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));

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

* [Bug libstdc++/105957] __n * sizeof(_Tp) might overflow under consteval context for std::allocator
  2022-06-13 19:10 [Bug libstdc++/105957] New: __n * sizeof(_Tp) might overflow under consteval context for std::allocator unlvsur at live dot com
@ 2022-06-14  9:32 ` redi at gcc dot gnu.org
  2022-06-14 20:19 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2022-06-14  9:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105957

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2022-06-14

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Testcase:

#include <memory>

constexpr auto f()
{
  std::allocator<long long> a;
  auto n = std::size_t(-1) / (sizeof(long long) - 1);
  auto p = a.allocate(n);
  a.deallocate(p, n);
  return n;
}
static_assert( f() );


In practice if the arithmetic wraps around and a smaller buffer is allocated,
any attempt to write beyond the allocated size would be detected in constant
evaluation anyway. So you'd still get a compilation error in most cases.

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

* [Bug libstdc++/105957] __n * sizeof(_Tp) might overflow under consteval context for std::allocator
  2022-06-13 19:10 [Bug libstdc++/105957] New: __n * sizeof(_Tp) might overflow under consteval context for std::allocator unlvsur at live dot com
  2022-06-14  9:32 ` [Bug libstdc++/105957] " redi at gcc dot gnu.org
@ 2022-06-14 20:19 ` cvs-commit at gcc dot gnu.org
  2022-06-14 20:20 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-06-14 20:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105957

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:0a9af7b4ef1b8aa85cc8820acf54d41d1569fc10

commit r13-1093-g0a9af7b4ef1b8aa85cc8820acf54d41d1569fc10
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Jun 14 14:37:25 2022 +0100

    libstdc++: Check for size overflow in constexpr allocation [PR105957]

    libstdc++-v3/ChangeLog:

            PR libstdc++/105957
            * include/bits/allocator.h (allocator::allocate): Check for
            overflow in constexpr allocation.
            * testsuite/20_util/allocator/105975.cc: New test.

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

* [Bug libstdc++/105957] __n * sizeof(_Tp) might overflow under consteval context for std::allocator
  2022-06-13 19:10 [Bug libstdc++/105957] New: __n * sizeof(_Tp) might overflow under consteval context for std::allocator unlvsur at live dot com
  2022-06-14  9:32 ` [Bug libstdc++/105957] " redi at gcc dot gnu.org
  2022-06-14 20:19 ` cvs-commit at gcc dot gnu.org
@ 2022-06-14 20:20 ` redi at gcc dot gnu.org
  2022-08-03 13:46 ` cvs-commit at gcc dot gnu.org
  2022-08-03 13:49 ` redi at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2022-06-14 20:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105957

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.2

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed on trunk. gcc-12 backport to follow.

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

* [Bug libstdc++/105957] __n * sizeof(_Tp) might overflow under consteval context for std::allocator
  2022-06-13 19:10 [Bug libstdc++/105957] New: __n * sizeof(_Tp) might overflow under consteval context for std::allocator unlvsur at live dot com
                   ` (2 preceding siblings ...)
  2022-06-14 20:20 ` redi at gcc dot gnu.org
@ 2022-08-03 13:46 ` cvs-commit at gcc dot gnu.org
  2022-08-03 13:49 ` redi at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-08-03 13:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105957

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:2ef2de76dae5cac14e0de77ca7205e43be03ab22

commit r12-8655-g2ef2de76dae5cac14e0de77ca7205e43be03ab22
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Jun 14 14:37:25 2022 +0100

    libstdc++: Check for size overflow in constexpr allocation [PR105957]

    libstdc++-v3/ChangeLog:

            PR libstdc++/105957
            * include/bits/allocator.h (allocator::allocate): Check for
            overflow in constexpr allocation.
            * testsuite/20_util/allocator/105975.cc: New test.

    (cherry picked from commit 0a9af7b4ef1b8aa85cc8820acf54d41d1569fc10)

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

* [Bug libstdc++/105957] __n * sizeof(_Tp) might overflow under consteval context for std::allocator
  2022-06-13 19:10 [Bug libstdc++/105957] New: __n * sizeof(_Tp) might overflow under consteval context for std::allocator unlvsur at live dot com
                   ` (3 preceding siblings ...)
  2022-08-03 13:46 ` cvs-commit at gcc dot gnu.org
@ 2022-08-03 13:49 ` redi at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2022-08-03 13:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105957

Jonathan Wakely <redi at gcc dot gnu.org> changed:

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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Backported for 12.2

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

end of thread, other threads:[~2022-08-03 13:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-13 19:10 [Bug libstdc++/105957] New: __n * sizeof(_Tp) might overflow under consteval context for std::allocator unlvsur at live dot com
2022-06-14  9:32 ` [Bug libstdc++/105957] " redi at gcc dot gnu.org
2022-06-14 20:19 ` cvs-commit at gcc dot gnu.org
2022-06-14 20:20 ` redi at gcc dot gnu.org
2022-08-03 13:46 ` cvs-commit at gcc dot gnu.org
2022-08-03 13:49 ` redi at gcc dot gnu.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).