public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/99418] New: sanitizer checks for accessing multidimentional VLA-array
@ 2021-03-05 19:11 vanyacpp at gmail dot com
  2021-03-06 22:53 ` [Bug sanitizer/99418] " vanyacpp at gmail dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: vanyacpp at gmail dot com @ 2021-03-05 19:11 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99418
           Summary: sanitizer checks for accessing multidimentional
                    VLA-array
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vanyacpp at gmail dot com
                CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at gcc dot gnu.org
  Target Milestone: ---

The example below accesses array past its size, but sanitizers don't show any
errors. If I change index m to m + 1 an error will be shown. This makes me
think that compiler does some checks, but perhaps they are incomplete for
multidimentional VLA-arrays.

GCC 10.2.

#include <string>

std::string shortest_match(size_t n, size_t m)
{
    std::string mas[n][m];
    mas[n - 1][m] = ""; // mas[n - 1][m + 1] will show an errors

    return mas[n - 1][m - 1];
}

int main()
{
    shortest_match(4, 3);
}

$ g++ -g -fsanitize=address,undefined -std=c++17 2.cpp && ./a.out 
AddressSanitizer:DEADLYSIGNAL
=================================================================
==26974==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc
0x7f59ea2ad2d6 bp 0x000000000000 sp 0x7ffc78389ea0 T0)
==26974==The signal is caused by a WRITE memory access.
==26974==Hint: address points to the zero page.
    #0 0x7f59ea2ad2d6 in std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned long,
unsigned long, char const*, unsigned long) (/lib/libstdc++.so.6+0x13c2d6)
    #1 0x401658 in shortest_match[abi:cxx11](unsigned long, unsigned long)
/home/ivan/2.cpp:6
    #2 0x4019eb in main /home/ivan/2.cpp:13
    #3 0x7f59e950ec7c in __libc_start_main (/lib/libc.so.6+0x23c7c)
    #4 0x4011a9 in _start (/home/ivan/a.out+0x4011a9)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/lib/libstdc++.so.6+0x13c2d6) in
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>
>::_M_replace(unsigned long, unsigned long, char const*, unsigned long)
==26974==ABORTING

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-03-09 15:48 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-05 19:11 [Bug sanitizer/99418] New: sanitizer checks for accessing multidimentional VLA-array vanyacpp at gmail dot com
2021-03-06 22:53 ` [Bug sanitizer/99418] " vanyacpp at gmail dot com
2021-03-07  7:44 ` vanyacpp at gmail dot com
2021-03-08  9:15 ` marxin at gcc dot gnu.org
2021-03-08 10:14 ` jakub at gcc dot gnu.org
2021-03-08 18:23 ` msebor at gcc dot gnu.org
2021-03-09  8:39 ` vanyacpp at gmail dot com
2021-03-09  8:47 ` vanyacpp at gmail dot com
2021-03-09  8:54 ` vanyacpp at gmail dot com
2021-03-09 15:48 ` [Bug sanitizer/99418] more cases where -fsanitize=bounds can check one-past-the-end accesses msebor at gcc dot gnu.org

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).