public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug sanitizer/102095] Returned reference to temporary not caught by -fsanitize=undefined
Date: Tue, 31 Aug 2021 08:25:43 +0000	[thread overview]
Message-ID: <bug-102095-4-nLUlCYIkc8@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-102095-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
-fsanitize=undefined is never meant to catch such bugs, -fsanitize=address is.
And it does catch that:
g++ -g -fsanitize=address -o /tmp/pr102095{,.C} -std=c++20;
ASAN_OPTIONS=detect_stack_use_after_return=1 /tmp/pr102095
1
=================================================================
==2328983==ERROR: AddressSanitizer: stack-use-after-return on address
0x7fbca4fec0a0 at pc 0x000000401773 bp 0x7ffeb2a60420 sp 0x7ffeb2a60418
READ of size 8 at 0x7fbca4fec0a0 thread T0
    #0 0x401772 in main /tmp/pr102095.C:22
    #1 0x7fbca86a01a1 in __libc_start_main (/lib64/libc.so.6+0x281a1)
    #2 0x4011dd in _start (/tmp/pr102095+0x4011dd)

Address 0x7fbca4fec0a0 is located in stack of thread T0 at offset 32 in frame
    #0 0x402f32 in std::enable_if<is_invocable_r_v<std::tuple<double const&>,
zip_bad<double const&>(std::function<double const& ()> const&)::{lambda()#1}&>,
std::tuple<double const&> >::type std::__invoke_r<std::tuple<double const&>,
zip_bad<double const&>(std::function<double const& ()>
const&)::{lambda()#1}&>(std::enable_if&&, (zip_bad<double
const&>(std::function<double const& ()> const&)::{lambda()#1}&)...)
/usr/include/c++/10/bits/invoke.h:103

  This frame has 1 object(s):
    [32, 40) '<unknown>' <== Memory access at offset 32 is inside this variable
HINT: this may be a false positive if your program uses some custom stack
unwind mechanism, swapcontext or vfork
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-use-after-return /tmp/pr102095.C:22 in main
Shadow bytes around the buggy address:
  0x0ff8149f57c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff8149f57d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff8149f57e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff8149f57f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff8149f5800: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
=>0x0ff8149f5810: f5 f5 f5 f5[f5]f5 f5 f5 00 00 00 00 00 00 00 00
  0x0ff8149f5820: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff8149f5830: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff8149f5840: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff8149f5850: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff8149f5860: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
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
  Shadow gap:              cc
==2328983==ABORTING

      parent reply	other threads:[~2021-08-31  8:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-27 11:28 [Bug sanitizer/102095] New: " loximann at gmail dot com
2021-08-31  8:15 ` [Bug sanitizer/102095] " redi at gcc dot gnu.org
2021-08-31  8:25 ` jakub at gcc dot gnu.org [this message]

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-102095-4-nLUlCYIkc8@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).