From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 13AAE3858023; Tue, 31 Aug 2021 08:25:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 13AAE3858023 From: "jakub at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: sanitizer X-Bugzilla-Version: 11.1.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Aug 2021 08:25:44 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102095 --- Comment #2 from Jakub Jelinek --- -fsanitize=3Dundefined is never meant to catch such bugs, -fsanitize=3Daddr= ess is. And it does catch that: g++ -g -fsanitize=3Daddress -o /tmp/pr102095{,.C} -std=3Dc++20; ASAN_OPTIONS=3Ddetect_stack_use_after_return=3D1 /tmp/pr102095 1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D2328983=3D=3DERROR: AddressSanitizer: stack-use-after-return on addre= ss 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 fra= me #0 0x402f32 in std::enable_if, zip_bad(std::function const&)::{lambda()#1= }&>, std::tuple >::type std::__invoke_r, zip_bad(std::function const&)::{lambda()#1}&>(std::enable_if&&, (zip_bad(std::function const&)::{lambda()#1}&)...) /usr/include/c++/10/bits/invoke.h:103 This frame has 1 object(s): [32, 40) '' <=3D=3D 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 =3D>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=20 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 =3D=3D2328983=3D=3DABORTING=