From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 553DC3858D39; Tue, 3 Oct 2023 21:24:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 553DC3858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696368285; bh=JpqFbTQ5XjTbt6zXSeSMpDQpx/inBX+ShazzwMzl+jY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=NhDl6hulAWCeM4oKF3sHhKp0ItR1sBbtReiGkwTWOrdfFdwSpvniUhbRUGOXCbpHe F6or503feVMwHzSyocf/neLLMaZVerm6NPDNLrRU/Oz1CDh95rHwwi+3YwoSpxA5OM /IxvURLtgUieZUtpaESkCqrPx9YKtMFWxKqIJ2yg= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/111685] Segfault while sorting on array element address Date: Tue, 03 Oct 2023 21:24:44 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 13.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D111685 --- Comment #5 from Andrew Pinski --- With -fsanitize=3Daddress we get this at runtime: ``` =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=3D1=3D=3DERROR: AddressSanitizer: stack-buffer-overflow on address 0x7f= c69190003c at pc 0x000000402d20 bp 0x7ffdf89976f0 sp 0x7ffdf89976e8 READ of size 4 at 0x7fc69190003c thread T0 #0 0x402d1f in void std::__unguarded_linear_insert >(in= t*, __gnu_cxx::__ops::_Val_comp_iter) (/app/output.s+0x402d1f) (BuildId: 644c16636015edebcd5c5ddf005f8c7778b15662) #1 0x40222f in void std::__insertion_sort >(i= nt*, int*, __gnu_cxx::__ops::_Iter_comp_iter) (/app/output.s+0x40222f) (BuildId: 644c16636015edebcd5c5ddf005f8c7778b15662) #2 0x401c23 in void std::__final_insertion_sort >(i= nt*, int*, __gnu_cxx::__ops::_Iter_comp_iter) (/app/output.s+0x401c23) (BuildId: 644c16636015edebcd5c5ddf005f8c7778b15662) #3 0x401875 in void std::__sort >(i= nt*, int*, __gnu_cxx::__ops::_Iter_comp_iter) (/app/output.s+0x401875) (BuildId: 644c16636015edebcd5c5ddf005f8c7778b15662) #4 0x401653 in void std::sort(int*, int*, main::{lambda(auto:1&&, auto:2&&)#1}) (/app/output.s+0x401653) (BuildId: 644c16636015edebcd5c5ddf005f8c7778b15662) #5 0x401506 in main (/app/output.s+0x401506) (BuildId: 644c16636015edebcd5c5ddf005f8c7778b15662) #6 0x7fc693b93082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId: 1878e6b475720c7c51969e69ab2d276fae6d1dee) #7 0x40122d in _start (/app/output.s+0x40122d) (BuildId: 644c16636015edebcd5c5ddf005f8c7778b15662) Address 0x7fc69190003c is located in stack of thread T0 at offset 60 in fra= me #0 0x4012f5 in main (/app/output.s+0x4012f5) (BuildId: 644c16636015edebcd5c5ddf005f8c7778b15662) This frame has 5 object(s): [32, 33) '' [48, 49) 'cmp' (line 13) [64, 76) 'anums' (line 10) <=3D=3D Memory access at offset 60 underflow= s this variable [96, 108) 'nums' (line 11) [128, 152) 'vnums' (line 9) 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-buffer-overflow (/app/output.s+0x402d1f) (BuildId: 644c16636015edebcd5c5ddf005f8c7778b15662) in void std::__unguarded_linear_insert >(in= t*, __gnu_cxx::__ops::_Val_comp_iter) Shadow bytes around the buggy address: 0x7fc6918ffd80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x7fc6918ffe00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x7fc6918ffe80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x7fc6918fff00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x7fc6918fff80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 =3D>0x7fc691900000: f1 f1 f1 f1 f8 f2 01[f2]00 04 f2 f2 00 04 f2 f2 0x7fc691900080: 00 00 00 f3 f3 f3 f3 f3 00 00 00 00 00 00 00 00 0x7fc691900100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x7fc691900180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x7fc691900200: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x7fc691900280: 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 =3D=3D1=3D=3DABORTING ```=