public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/97023] New: missing warning on buffer overflow in chained mempcpy Date: Fri, 11 Sep 2020 17:35:10 +0000 [thread overview] Message-ID: <bug-97023-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97023 Bug ID: 97023 Summary: missing warning on buffer overflow in chained mempcpy Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- -Wstringop-overflow successfully diagnoses a buffer overflow by the second in a chain of calls to stpcpy but fails to detect the same bug in calls to mempcpy because it doesn't track function arguments that are returned from builti-ins like mempcpy or memchr. $ cat z.c && gcc -O2 -S z.c char a[7]; void* f (void) { void *p = __builtin_stpcpy (a, "123"); p = __builtin_stpcpy (p, "4567"); // warning (good) return p; } void* g (void) { void *p = __builtin_mempcpy (a, "123", 3); p = __builtin_mempcpy (p, "4567", 5); // missing warning return p; } z.c: In function ‘f’: z.c:5:13: warning: ‘__builtin_memcpy’ writing 5 bytes into a region of size 4 [-Wstringop-overflow=] 5 | void *p = __builtin_stpcpy (a, "123"); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ z.c:1:6: note: at offset 3 to object ‘a’ with size 7 declared here 1 | char a[7]; | ^
next reply other threads:[~2020-09-11 17:35 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-09-11 17:35 msebor at gcc dot gnu.org [this message] 2020-09-11 17:35 ` [Bug middle-end/97023] " msebor at gcc dot gnu.org 2020-09-15 19:18 ` msebor at gcc dot gnu.org 2020-10-12 15:07 ` cvs-commit at gcc dot gnu.org 2020-10-12 15:11 ` msebor 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-97023-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).