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

--- Comment #6 from Neil Carlson <neil.n.carlson at gmail dot com> ---
Here's a variation of the example involving arrays. I expect the source of the
failure here is the same, but I want to be sure this example is also fixed by
the eventual patch.

program main
  call run
contains
  subroutine run
    class(*), allocatable :: y(:)
    call foo(['fubar','fubar'], y)
  end subroutine 
  subroutine foo(a, b)
    class(*), intent(in) :: a(:)
    class(*), allocatable :: b(:)
    b = a
    !allocate(b, source=a) ! VALGRIND REPORTS NO INVALID WRITES 
  end subroutine
end program

Compiled with -fsanitize=address and executed gives this:

==1338704==ERROR: AddressSanitizer: heap-buffer-overflow on address
0x602000000072 at pc 0x7fb456a4c8d1 bp 0x7ffcfd375d50 sp 0x7ffcfd375500
WRITE of size 5 at 0x602000000072 thread T0
    #0 0x7fb456a4c8d0 in __interceptor_memmove
../../../../libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:810
    #1 0x4012d4 in __copy_character_1 /home/nnc/Codes/petaca/bugs/fubar.f90:1
    #2 0x401c9f in foo /home/nnc/Codes/petaca/bugs/fubar.f90:11
    #3 0x4023e8 in run /home/nnc/Codes/petaca/bugs/fubar.f90:6
    #4 0x40137e in MAIN__ /home/nnc/Codes/petaca/bugs/fubar.f90:2
    #5 0x4027a1 in main /home/nnc/Codes/petaca/bugs/fubar.f90:2
    #6 0x7fb4563ff149 in __libc_start_call_main (/lib64/libc.so.6+0x28149)
    #7 0x7fb4563ff20a in __libc_start_main_impl (/lib64/libc.so.6+0x2820a)
    #8 0x401184 in _start (/home/nnc/Codes/petaca/bugs/a.out+0x401184)

0x602000000072 is located 0 bytes to the right of 2-byte region
[0x602000000070,0x602000000072)
allocated by thread T0 here:
    #0 0x7fb456abd69f in __interceptor_malloc
../../../../libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x401965 in foo /home/nnc/Codes/petaca/bugs/fubar.f90:11
    #2 0x4023e8 in run /home/nnc/Codes/petaca/bugs/fubar.f90:6
    #3 0x40137e in MAIN__ /home/nnc/Codes/petaca/bugs/fubar.f90:2
    #4 0x4027a1 in main /home/nnc/Codes/petaca/bugs/fubar.f90:2
    #5 0x7fb4563ff149 in __libc_start_call_main (/lib64/libc.so.6+0x28149)
    #6 0x7fb4563ff20a in __libc_start_main_impl (/lib64/libc.so.6+0x2820a)
    #7 0x401184 in _start (/home/nnc/Codes/petaca/bugs/a.out+0x401184)

SUMMARY: AddressSanitizer: heap-buffer-overflow
../../../../libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:810
in __interceptor_memmove

Reply via email to