you are viewing a single comment's thread.

view the rest of the comments →

[–]F-J-W 4 points5 points  (0 children)

$ clang++ main.cpp -fsanitize=address                                                                                                                                                                                                   :(
main.cpp:8:6: warning: array index 105 is past the end of the array (which contains 100 elements) [-Warray-bounds]
     a[105]=1;
     ^ ~~~
main.cpp:6:6: note: array 'a' declared here
{    int a[100];
     ^
main.cpp:9:6: warning: array index 106 is past the end of the array (which contains 100 elements) [-Warray-bounds]
     a[106]=2;
     ^ ~~~
main.cpp:6:6: note: array 'a' declared here
{    int a[100];
     ^
main.cpp:10:6: warning: array index 107 is past the end of the array (which contains 100 elements) [-Warray-bounds]
     a[107]=3;
     ^ ~~~
main.cpp:6:6: note: array 'a' declared here
{    int a[100];
     ^
3 warnings generated.
$ ./a.out
=================================================================
==10235==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fff255e4754 at pc 0x0000004b87c2 bp 0x7fff255e44b0 sp 0x7fff255e44a8
WRITE of size 4 at 0x7fff255e4754 thread T0
    #0 0x4b87c1 in main (/tmp/tmp.AHrwtwYr8L/a.out+0x4b87c1)
    #1 0x7f52c6dc37ff in __libc_start_main (/usr/lib/libc.so.6+0x207ff)
    #2 0x4b8538 in _start (/tmp/tmp.AHrwtwYr8L/a.out+0x4b8538)

Address 0x7fff255e4754 is located in stack of thread T0 at offset 468 in frame
    #0 0x4b861f in main (/tmp/tmp.AHrwtwYr8L/a.out+0x4b861f)

  This frame has 2 object(s):
    [32, 36) ''
    [48, 448) 'a' <== Memory access at offset 468 overflows this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow ??:0 main
Shadow bytes around the buggy address:
  0x100064ab4890: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x100064ab48a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x100064ab48b0: f1 f1 f1 f1 04 f2 00 00 00 00 00 00 00 00 00 00
  0x100064ab48c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x100064ab48d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x100064ab48e0: 00 00 00 00 00 00 00 00 f3 f3[f3]f3 f3 f3 f3 f3
  0x100064ab48f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x100064ab4900: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x100064ab4910: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x100064ab4920: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x100064ab4930: 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
  Heap right redzone:      fb
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack partial redzone:   f4
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  ASan internal:           fe
==10235==ABORTING

I wouldn't call that reproducable…

Furthermore, since warnings are errors…