public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.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	[thread overview]
Message-ID: <bug-111685-4-Dm0mVW8Szh@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-111685-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
With -fsanitize=address we get this at runtime:
```
=================================================================
==1==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fc69190003c
at pc 0x000000402d20 bp 0x7ffdf89976f0 sp 0x7ffdf89976e8
READ of size 4 at 0x7fc69190003c thread T0
    #0 0x402d1f in void std::__unguarded_linear_insert<int*,
__gnu_cxx::__ops::_Val_comp_iter<main::{lambda(auto:1&&, auto:2&&)#1}> >(int*,
__gnu_cxx::__ops::_Val_comp_iter<main::{lambda(auto:1&&, auto:2&&)#1}>)
(/app/output.s+0x402d1f) (BuildId: 644c16636015edebcd5c5ddf005f8c7778b15662)
    #1 0x40222f in void std::__insertion_sort<int*,
__gnu_cxx::__ops::_Iter_comp_iter<main::{lambda(auto:1&&, auto:2&&)#1}> >(int*,
int*, __gnu_cxx::__ops::_Iter_comp_iter<main::{lambda(auto:1&&, auto:2&&)#1}>)
(/app/output.s+0x40222f) (BuildId: 644c16636015edebcd5c5ddf005f8c7778b15662)
    #2 0x401c23 in void std::__final_insertion_sort<int*,
__gnu_cxx::__ops::_Iter_comp_iter<main::{lambda(auto:1&&, auto:2&&)#1}> >(int*,
int*, __gnu_cxx::__ops::_Iter_comp_iter<main::{lambda(auto:1&&, auto:2&&)#1}>)
(/app/output.s+0x401c23) (BuildId: 644c16636015edebcd5c5ddf005f8c7778b15662)
    #3 0x401875 in void std::__sort<int*,
__gnu_cxx::__ops::_Iter_comp_iter<main::{lambda(auto:1&&, auto:2&&)#1}> >(int*,
int*, __gnu_cxx::__ops::_Iter_comp_iter<main::{lambda(auto:1&&, auto:2&&)#1}>)
(/app/output.s+0x401875) (BuildId: 644c16636015edebcd5c5ddf005f8c7778b15662)
    #4 0x401653 in void std::sort<int*, main::{lambda(auto:1&&,
auto:2&&)#1}>(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 frame
    #0 0x4012f5 in main (/app/output.s+0x4012f5) (BuildId:
644c16636015edebcd5c5ddf005f8c7778b15662)

  This frame has 5 object(s):
    [32, 33) '<unknown>'
    [48, 49) 'cmp' (line 13)
    [64, 76) 'anums' (line 10) <== Memory access at offset 60 underflows 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<int*,
__gnu_cxx::__ops::_Val_comp_iter<main::{lambda(auto:1&&, auto:2&&)#1}> >(int*,
__gnu_cxx::__ops::_Val_comp_iter<main::{lambda(auto:1&&, auto:2&&)#1}>)
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
=>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 
  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
==1==ABORTING
```

  parent reply	other threads:[~2023-10-03 21:24 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-03 18:57 [Bug c++/111685] New: " knoepfel at fnal dot gov
2023-10-03 19:06 ` [Bug libstdc++/111685] " pinskia at gcc dot gnu.org
2023-10-03 19:10 ` pinskia at gcc dot gnu.org
2023-10-03 19:14 ` knoepfel at fnal dot gov
2023-10-03 19:19 ` knoepfel at fnal dot gov
2023-10-03 21:24 ` pinskia at gcc dot gnu.org [this message]
2023-10-03 21:37 ` pinskia at gcc dot gnu.org
2023-10-04  1:35 ` xry111 at gcc dot gnu.org
2023-10-04  9:48 ` redi at gcc dot gnu.org
2023-10-04 10:06 ` redi at gcc dot gnu.org
2023-10-04 17:46 ` fchelnokov at gmail dot com
2023-10-05 19:27 ` knoepfel at fnal dot gov
2023-10-06 10:10 ` fchelnokov at gmail dot com

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-111685-4-Dm0mVW8Szh@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).