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

--- Comment #13 from Martin Liška <marxin at gcc dot gnu.org> ---
Not true for:

$ cat global5.c
const char c1[] = "a";

int main()
{
  return *(&c1[0]+3);
}

$ gcc-8 -fsanitize=address global5.c -fno-common && ./a.out 
=================================================================
==13012==ERROR: AddressSanitizer: global-buffer-overflow on address
0x000000402023 at pc 0x00000040118f bp 0x7fffffffdc00 sp 0x7fffffffdbf8
READ of size 1 at 0x000000402023 thread T0
    #0 0x40118e in main (/home/marxin/Programming/testcases/a.out+0x40118e)
    #1 0x7ffff73b4b7a in __libc_start_main ../csu/libc-start.c:308
    #2 0x4010a9 in _start (/home/marxin/Programming/testcases/a.out+0x4010a9)

0x000000402023 is located 1 bytes to the right of global variable 'c1' defined
in 'global5.c:1:12' (0x402020) of size 2
  'c1' is ascii string 'a'
SUMMARY: AddressSanitizer: global-buffer-overflow
(/home/marxin/Programming/testcases/a.out+0x40118e) in main
Shadow bytes around the buggy address:
  0x0000800783b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0000800783c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0000800783d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0000800783e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0000800783f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x000080078400: 00 00 00 00[02]f9 f9 f9 f9 f9 f9 f9 00 00 00 00
  0x000080078410: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x000080078420: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x000080078430: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x000080078440: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x000080078450: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Thus the dummies will be really needed.

Reply via email to