public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/102217] co_awaiting a temporary produced by ternary operator crashes (double-free)
Date: Wed, 02 Nov 2022 11:41:53 +0000	[thread overview]
Message-ID: <bug-102217-4-FgHVcTJVwY@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-102217-4@http.gcc.gnu.org/bugzilla/>

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-valid-code
   Last reconfirmed|                            |2022-11-02
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
=================================================================
==624580==ERROR: AddressSanitizer: heap-use-after-free on address
0x606000000028 at pc 0x0000004042b1 bp 0x7ffe18357490 sp 0x7ffe18357488
READ of size 8 at 0x606000000028 thread T0
    #0 0x4042b0 in std::__n4861::coroutine_handle<Co::promise<Foo,
Co::Task<Foo> > >::destroy() const
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/coroutine:246
    #1 0x403cb7 in Co::UniqueHandle<Co::promise<Foo, Co::Task<Foo> >
>::~UniqueHandle() /tmp/cocrash.cxx:37
    #2 0x403767 in Co::Task<Foo>::~Task() /tmp/cocrash.cxx:135
    #3 0x402a47 in FooC /tmp/cocrash.cxx:171
    #4 0x4018c2 in FooA /tmp/cocrash.cxx:160
    #5 0x402c11 in FooC /tmp/cocrash.cxx:168
    #6 0x403501 in std::__n4861::coroutine_handle<void>::resume() const
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/coroutine:135
    #7 0x402f84 in main /tmp/cocrash.cxx:177
    #8 0x7f66323e750f in __libc_start_call_main (/lib64/libc.so.6+0x2950f)
    #9 0x7f66323e75c8 in __libc_start_main_impl (/lib64/libc.so.6+0x295c8)
    #10 0x4011b4 in _start (/tmp/a.out+0x4011b4)

0x606000000028 is located 8 bytes inside of 56-byte region
[0x606000000020,0x606000000058)
freed by thread T0 here:
    #0 0x7f66329bcbb8 in operator delete(void*)
../../../../gcc-12.1.0/libsanitizer/asan/asan_new_delete.cpp:152
    #1 0x401981 in FooA /tmp/cocrash.cxx:162
    #2 0x401a38 in FooA /tmp/cocrash.cxx:160
    #3 0x4042b9 in std::__n4861::coroutine_handle<Co::promise<Foo,
Co::Task<Foo> > >::destroy() const
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/coroutine:246
    #4 0x403cb7 in Co::UniqueHandle<Co::promise<Foo, Co::Task<Foo> >
>::~UniqueHandle() /tmp/cocrash.cxx:37
    #5 0x403767 in Co::Task<Foo>::~Task() /tmp/cocrash.cxx:135
    #6 0x4029ff in FooC /tmp/cocrash.cxx:171
    #7 0x4018c2 in FooA /tmp/cocrash.cxx:160
    #8 0x402c11 in FooC /tmp/cocrash.cxx:168
    #9 0x403501 in std::__n4861::coroutine_handle<void>::resume() const
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/coroutine:135
    #10 0x402f84 in main /tmp/cocrash.cxx:177
    #11 0x7f66323e750f in __libc_start_call_main (/lib64/libc.so.6+0x2950f)

previously allocated by thread T0 here:
    #0 0x7f66329bc178 in operator new(unsigned long)
../../../../gcc-12.1.0/libsanitizer/asan/asan_new_delete.cpp:95
    #1 0x40129f in FooA() /tmp/cocrash.cxx:162
    #2 0x4027c2 in FooC /tmp/cocrash.cxx:171
    #3 0x403501 in std::__n4861::coroutine_handle<void>::resume() const
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/coroutine:135
    #4 0x402f84 in main /tmp/cocrash.cxx:177
    #5 0x7f66323e750f in __libc_start_call_main (/lib64/libc.so.6+0x2950f)

SUMMARY: AddressSanitizer: heap-use-after-free
/home/jwakely/gcc/12.1.0/include/c++/12.1.0/coroutine:246 in
std::__n4861::coroutine_handle<Co::promise<Foo, Co::Task<Foo> > >::destroy()
const
Shadow bytes around the buggy address:
  0x0c0c7fff7fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c0c7fff7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c0c7fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c0c7fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c0c7fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c0c7fff8000: fa fa fa fa fd[fd]fd fd fd fd fd fa fa fa fa fa
  0x0c0c7fff8010: fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa fa
  0x0c0c7fff8020: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c0c7fff8030: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c0c7fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c0c7fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==624580==ABORTING

  parent reply	other threads:[~2022-11-02 11:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-06 11:01 [Bug c++/102217] New: " max at duempel dot org
2021-11-19 11:49 ` [Bug c++/102217] " max at duempel dot org
2021-11-19 11:52 ` max at duempel dot org
2022-03-04 13:53 ` kux@smart-hmi.de
2022-11-02 11:41 ` redi at gcc dot gnu.org [this message]
2022-11-02 11:43 ` redi at gcc dot gnu.org
2022-11-24  1:59 ` pinskia at gcc dot gnu.org
2024-02-05 14:20 ` redi at gcc dot gnu.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-102217-4-FgHVcTJVwY@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.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: link
Be 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).