public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "nszabolcs at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/64964] New: -D_FORTIFY_SOURCE=2 passes incorrect length to _chk functions in some cases Date: Fri, 06 Feb 2015 18:03:00 -0000 [thread overview] Message-ID: <bug-64964-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64964 Bug ID: 64964 Summary: -D_FORTIFY_SOURCE=2 passes incorrect length to _chk functions in some cases Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: nszabolcs at gmail dot com in the following simple testcase the valid length of x.a+1 is 1, but 2 is passed to __strcpy_chk according to the asm (gcc-4.8 gets it right, glibc debug/tst-chk3 and debug/tst-chk6 testcases fail now with gcc built from trunk) at runtime x.b[0] gets clobbered with 0 and there is no failure reported. $ cat chk.c #include <string.h> int main() { char *volatile s = "A"; struct { char a[2]; char b[1]; } x; strcpy(x.a+1, s); return 0; } $ gcc -D_FORTIFY_SOURCE=2 -O -S chk.c $ cat chk.s .file "chk.c" .section .rodata.str1.1,"aMS",@progbits,1 .LC0: .string "A" .text .globl main .type main, @function main: .LFB22: .cfi_startproc subq $24, %rsp .cfi_def_cfa_offset 32 movq $.LC0, 8(%rsp) movq 8(%rsp), %rsi movl $2, %edx leaq 1(%rsp), %rdi call __strcpy_chk movl $0, %eax addq $24, %rsp .cfi_def_cfa_offset 8 ret .cfi_endproc .LFE22: .size main, .-main .ident "GCC: (GNU) 5.0.0 20150205 (experimental)" .section .note.GNU-stack,"",@progbits
next reply other threads:[~2015-02-06 18:03 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-02-06 18:03 nszabolcs at gmail dot com [this message] 2015-02-09 14:33 ` [Bug c/64964] " rguenth at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-64964-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).