http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50460

             Bug #: 50460
           Summary: [4.7 Regression]
                    __builtin___strcpy_chk/__builtin_object_size don't
                    work
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: hjl.to...@gmail.com


On Linux/x86, revision 178028 gave

[hjl@gnu-34 gcc]$ cat ~/tmp/foo.c
const char *str1 = "JIHGFEDCBA";
extern __inline __attribute__ ((__always_inline__)) __attribute__
((__artificial__)) char *
__attribute__ ((__nothrow__)) strcpy (char *__restrict __dest, __const char
*__restrict __src)
{
  return __builtin___strcpy_chk (__dest, __src, __builtin_object_size (__dest,
2 > 1));
}
int
main ()
{
  struct A { char buf1[9]; char buf2[1]; } a;
  strcpy (a.buf1 + (0 + 4), str1 + 5);
  return 0;
}
[hjl@gnu-34 gcc]$ ./xgcc -B./ -O2  ~/tmp/foo.c
[hjl@gnu-34 gcc]$ ./a.out 
[hjl@gnu-34 gcc]$ 

instead of

[hjl@gnu-34 gcc]$ ./a.out 
*** buffer overflow detected ***: ./a.out terminated
======= Backtrace: =========
/lib64/libc.so.6(__fortify_fail+0x37)[0x3e56103ca7]
/lib64/libc.so.6[0x3e56101c20]
./a.out[0x40041e]
/lib64/libc.so.6(__libc_start_main+0xed)[0x3e560215bd]
./a.out[0x400451]
======= Memory map: ========
00400000-00401000 r-xp 00000000 08:11 52433950                          
/export/gnu/import/svn/gcc-test-ia32corei7/bld/gcc/a.out
00600000-00601000 rw-p 00000000 08:11 52433950                          
/export/gnu/import/svn/gcc-test-ia32corei7/bld/gcc/a.out
00a33000-00a54000 rw-p 00000000 00:00 0                                  [heap]
3e55c00000-3e55c22000 r-xp 00000000 08:06 392457                        
/lib64/ld-2.14.90.so
3e55e21000-3e55e22000 r--p 00021000 08:06 392457                        
/lib64/ld-2.14.90.so
3e55e22000-3e55e23000 rw-p 00022000 08:06 392457                        
/lib64/ld-2.14.90.so
3e55e23000-3e55e24000 rw-p 00000000 00:00 0 
3e56000000-3e561a6000 r-xp 00000000 08:06 392458                        
/lib64/libc-2.14.90.so
3e561a6000-3e563a5000 ---p 001a6000 08:06 392458                        
/lib64/libc-2.14.90.so
3e563a5000-3e563a9000 r--p 001a5000 08:06 392458                        
/lib64/libc-2.14.90.so
3e563a9000-3e563aa000 rw-p 001a9000 08:06 392458                        
/lib64/libc-2.14.90.so
3e563aa000-3e563b0000 rw-p 00000000 00:00 0 
3e57800000-3e57815000 r-xp 00000000 08:06 392602                        
/lib64/libgcc_s-4.6.0-20110603.so.1
3e57815000-3e57a14000 ---p 00015000 08:06 392602                        
/lib64/libgcc_s-4.6.0-20110603.so.1
3e57a14000-3e57a15000 rw-p 00014000 08:06 392602                        
/lib64/libgcc_s-4.6.0-20110603.so.1
7fb292f73000-7fb292f76000 rw-p 00000000 00:00 0 
7fb292f93000-7fb292f95000 rw-p 00000000 00:00 0 
7fff0d60a000-7fff0d62b000 rw-p 00000000 00:00 0                         
[stack]
7fff0d68a000-7fff0d68b000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                 
[vsyscall]
Aborted (core dumped)
[hjl@gnu-34 gcc]$ 

Revision 177983 is OK.

Reply via email to